Moving through files in a folder

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tig201
    New Member
    • Mar 2007
    • 103

    Moving through files in a folder

    I am trying to go through the files in a folder and rename them but I am getting the error "Run-Time Error 5: Invalid procedure call or argument" on this bit of code
    Code:
    Dim myFileSysObj As New FileSystemObject, myFile As File, myFolder As Folder
    ...............
    For Cnt = 1 To myFolder.Files.Count Step 1
    ->  Set myFile = myFileSysObj.GetFile(myFolder.Files.Item(Cnt))
    Next Cnt
    .........
    can anybody explain this.
    Thanks
  • SanjuMtr
    New Member
    • Mar 2007
    • 47

    #2
    Originally posted by Tig201
    I am trying to go through the files in a folder and rename them but I am getting the error "Run-Time Error 5: Invalid procedure call or argument" on this bit of code
    Code:
    Dim myFileSysObj As New FileSystemObject, myFile As File, myFolder As Folder
    ...............
    For Cnt = 1 To myFolder.Files.Count Step 1
    ->  Set myFile = myFileSysObj.GetFile(myFolder.Files.Item(Cnt))
    Next Cnt
    .........
    can anybody explain this.
    Thanks
    Hi,
    Actually U did n't inatialized the Folder Path as well as Files from Specific Folder
    I am giving u a sample code hope You will understand it. & fulfill your requiremnet
    Code:
    Dim fsys As New FileSystemObject
     Dim fld As Folder
     Dim FLS As Files
     Dim Fl As File
     
     Set fld = fsys.GetFolder("C:\CA_ADVIC\Output\")
     Set FLS = fld.Files
     For Each Fl In FLS
      Combo1.AddItem Fl.Name
     Next
     If Combo1.ListCount > 0 Then Combo1.ListIndex = 0
    try it .good luck. Wait for your responce.

    Comment

    • Tig201
      New Member
      • Mar 2007
      • 103

      #3
      Thanks that did the trick

      Comment

      Working...