Results 1 to 9 of 9

Thread: Filenames beggining with...

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    49

    Filenames beggining with...

    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?

  2. #2

  3. #3
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Re: Filenames beggining with...

    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
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  4. #4
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Re: Filenames beggining with...

    Or just ask Rhino ... (trigger is his middle name)
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  5. #5

  6. #6

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    49

    Re: Filenames beggining with...

    does this not work with the FileCopy Function??

  7. #7

  8. #8

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    49

    Re: Filenames beggining with...

    then how do i copy all files beginning with a certain string? haha

  9. #9
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Filenames beggining with...

    Here is one way:
    VB Code:
    1. Public Sub CopyAllFiles(strSourceFolder As String, _
    2.                         strDestFolder As String, _
    3.                         Optional sBeginsWith As String, _
    4.                         Optional sContains As String, _
    5.                         Optional sEndsWith As String, _
    6.                         Optional sExt As String)
    7. '=========================================================
    8. Dim strFile As String
    9.  
    10. On Error GoTo ErrClear
    11.  
    12.     If Not Right(strSourceFolder, 1) = "\" Then strSourceFolder = strSourceFolder & "\"
    13.     If Not Right(strDestFolder, 1) = "\" Then strDestFolder = strDestFolder & "\"
    14.    
    15.     strFile = Dir(strSourceFolder, vbNormal)
    16.     Do While strFile <> ""
    17.         If strFile <> "." And strFile <> ".." Then
    18.             If Not Trim(sBeginsWith) = "" Then
    19.                 If UCase(Left(strFile, Len(Trim(sBeginsWith)))) = UCase(Trim(sBeginsWith)) Then
    20.                     FileCopy strSourceFolder & strFile, strDestFolder & strFile
    21.                 End If
    22.             End If
    23.         End If
    24.         strFile = Dir
    25.     Loop
    26.     Exit Sub
    27.    
    28. ErrClear:
    29. '-----------
    30.     Err.Clear
    31.     Resume Next
    32.  
    33. End Sub
    Sample from above will work to some extent but KIM that you may need to modify it ...

    Good luck

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width