In MS-DOS there is an option to delete all files that have filenames in a directory starting with, for example, “TEST” by using the command “del TEST*”. Is there a way to do this type of command in Visual Basic?
Printable View
In MS-DOS there is an option to delete all files that have filenames in a directory starting with, for example, “TEST” by using the command “del TEST*”. Is there a way to do this type of command in Visual Basic?
You can use the dame format with the File System Object (FSO) I believe. You will need to have the scrun.dll reference loaded to be able to access it though. There are tons of examples in the forum - just do a search
Yes there is:
VB Code:
Private Sub Command1_Click() Kill "c:\temp\*.txt" 'or Kill "c:\temp\test*.*" 'or .... End Sub
Or just ask Rhino ... :bigyello: (trigger is his middle name)
:p :p :p
does this not work with the FileCopy Function??
No ... Sorry.
then how do i copy all files beginning with a certain string? haha
Here is one way:
Sample from above will work to some extent but KIM that you may need to modify it ...VB Code:
Public Sub CopyAllFiles(strSourceFolder As String, _ strDestFolder As String, _ Optional sBeginsWith As String, _ Optional sContains As String, _ Optional sEndsWith As String, _ Optional sExt As String) '========================================================= Dim strFile As String On Error GoTo ErrClear If Not Right(strSourceFolder, 1) = "\" Then strSourceFolder = strSourceFolder & "\" If Not Right(strDestFolder, 1) = "\" Then strDestFolder = strDestFolder & "\" strFile = Dir(strSourceFolder, vbNormal) Do While strFile <> "" If strFile <> "." And strFile <> ".." Then If Not Trim(sBeginsWith) = "" Then If UCase(Left(strFile, Len(Trim(sBeginsWith)))) = UCase(Trim(sBeginsWith)) Then FileCopy strSourceFolder & strFile, strDestFolder & strFile End If End If End If strFile = Dir Loop Exit Sub ErrClear: '----------- Err.Clear Resume Next End Sub
Good luck