VB 6.0 question RE: GetFolder

Discussion in 'OT Technology' started by disc108, Aug 2, 2003.

  1. disc108

    disc108 New Member

    Joined:
    Dec 31, 2001
    Messages:
    4,440
    Likes Received:
    0
    I'm trying to get my program to cycle through a directory and for every directory that is numeric, call the rename function.

    What am I missing in this code? i can't get it to compile. I've never used GetFolder before and MSDN isnt much help for what i'm trying to do. do i need to declare Flder as Folder?

    Code:
    
    Dim Flder As Folder
    Dim DirectoryFolder
    
      Set DirectoryFolder = fsoGetFolder.GetFolder("\\svdata1\pos\oprogressive_reload")
      
      For Each Flder In DirectoryFolder
        If Numeric(Flder.Name) Then
            
            Rename CStr(Flder.Name)
        
        End If
      Next
    
     
    Last edited: Aug 2, 2003
  2. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    you forgot to declare and initialize your file system object... also make sure that under project -> references that you have "Microsoft Scripting Runtime" selected

    Code:
    Private Sub Command1_Click()
    Dim Flder As Folder
    Dim DirectoryFolder As Folder
    Dim fsoGetFolder As FileSystemObject
    Dim icount As Integer
    
      icount = 0
    
    Set fsoGetFolder = New FileSystemObject
      Set DirectoryFolder = fsoGetFolder.GetFolder("D:\Temp")
      
      
      For Each Flder In DirectoryFolder.SubFolders
        If IsNumeric(Flder.Name) Then
            
            Flder.Name = "new name" + CStr(icount)
            icount = icount + 1
        End If
      Next
    
    End Sub
    

    edit: shit, i fucked up... the above code works :)
     

Share This Page