Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Rename files

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,34392
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Rename files
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Rename files - 5/11/2006 7:22:09 AM   
  uracorpse

 

Posts: 1
Score: 0
Joined: 5/11/2006
Status: offline
I have a script that renames files by appending the creation date to the beginning of the file name. As it is I have a section for each group folder. What I would like is to have it search through one folder and change most of the files in all the subfolders. The catch is there are two directories that this shouldn't be done to so I would want the script to skip those two folders but get everything else. Is this possible?
The directory structure is similiar to this:
    MainFolder
         Folder 1
              Folder1a
         Folder 2
              Folder2a
         Folder 3 <-----skip

My current script is like this (I have pasted only a couple sections):

    ' Folder1 Section ********************************

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

    Set FileList = objWMIService.ExecQuery _
        ("ASSOCIATORS OF {Win32_Directory.Name='C:\Inetpub\ftproot\Folder1'} Where " _
            & "ResultClass = CIM_DataFile")

    For Each objFile In FileList
        strEnd = Right(objFile.Name, 12)
        strDate = Left(objFile.CreationDate, 8)
        strNewName = objFile.Drive & objFile.Path & strDate & strend
        errResult = objFile.Rename(strNewName)
    Next

    ' Folder2 Section ***********************************

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

    Set FileList = objWMIService.ExecQuery _
        ("ASSOCIATORS OF {Win32_Directory.Name='C:\Inetpub\ftproot\Folder2'} Where " _
            & "ResultClass = CIM_DataFile")

    For Each objFile In FileList
        strEnd = Right(objFile.Name, 12)
        strDate = Left(objFile.CreationDate, 8)
        strNewName = objFile.Drive & objFile.Path & strDate & strend
        errResult = objFile.Rename(strNewName)
    Next

Thanks,
Rob
 
 
Post #: 1
 
 RE: Rename files - 5/11/2006 7:43:53 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
Search thes fora for recursion. You should find plenty of examples of doing something for all the subfolders. Just check the name of the file with an If-Then before you rename it to exclude the ones you don't want to rename.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to uracorpse)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Rename files Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts