Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rename folders 2

Status
Not open for further replies.

pbuddy2007

Technical User
Feb 9, 2008
17
0
0
CA
I have a folder containing a lot of subfolders ( 1 level down only). All of them are named on the format DDMMYYYY but I'`d like to change them all to YYYY_MM_DD

I can't figure out how to do it, I'm sure it's a simple routine but I tried everything
 
One way is to use the FSO (FileSystemObject) to do your rename/move.

Another way would be to generate a BAT File then execute that via Shell32.

"If I were to wake up with my head sewn to the carpet, I wouldn't be more surprised than I am right now.
 
I tried with FSO but I'm always getting coding errors and gave up.
 
Like what? Lets take a look and see what we can do to iron it out. Could you post the code and error?

"If I were to wake up with my head sewn to the carpet, I wouldn't be more surprised than I am right now.
 
Something like this;

Dim fso As New fileSystemObject
Dim fld As Folder
Dim fil As File
Dim subFolder As Folder
Dim newName as string

Set fld = fso.GetFolder("C:\temp\")
For Each subFolder In fld.SubFolders
newname = "C:\Temp\Whatever"
subFolder.Move (newname)

Next


Don't forget Reference to 'Microsoft Scripting Runtime'
 
The problem is that obviously the folder gets locked the moment you address it directly. You have to move it using the fso directly. This here does work:

Code:
Dim fso As FileSystemObject, f As Folder, sf As Folder
Dim newname as String

Set fso = New FileSystemObject
Set f = fso.GetFolder("C:\Temp")
For Each sf In f.SubFolders
    newname = sf.Name
    newname = Right(newname, 4) & "_" & Mid(newname, 3, 2) & "_" & Left(newname, 2)
    fso.MoveFolder sf.Path, f.Path & "\" & newname
Next sf

;-)

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top