Hi Guys,
I am trying to write script that will rename all folders in a subfolder. Currently the folders all have a time stamp name. 2013-10-07-14-22 for example. I am hoping to find a way to rename all these folders with a code given by the user and then a sequence number starting at 001.
For example - 130012-001
I know how to batch rename folders by replacing a known string with user input but it's replacing an unknown string with a value from user input plus a sequence number that is giving me trouble.
Using the script below I have been able to do this with all files within a folder -
strJobname = InputBox ("PLEASE ENTER THE JOB CODE")
Const adVarChar = 200
Const MaxCharacters = 255
Set DataList = CreateObject("ADOR.Recordset")
DataList.Fields.Append "FileName", adVarChar, MaxCharacters
DataList.Fields.Append "FileDate", adVarChar, MaxCharacters
DataList.Open
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\Users\STUDIO 16\Desktop\BACKUP\WEB JPEGS\")
Set colFiles = objFolder.Files
For Each objFile in colFiles
DataList.AddNew
DataList("FileName") = objFile.Path
'DataList("FileDate") = objFile.DateCreated
DataList.Update
Next
DataList.Sort = "FileName"
DataList.MoveFirst
i = 1
Do Until DataList.EOF
If i < 10 Then
x = CStr("00" & i)
ElseIf i < 100 Then
x = CStr("0" & i)
ElseIf i < 1000 Then
x = CStr("" & i)
Else
x = i
End If
strNewName = "C:\Users\STUDIO 16\Desktop\BACKUP\WEB JPEGS\" & ".jpg"
objFSO.MoveFile DataList.Fields.Item("FileName"), strNewName
i = i + 1
DataList.MoveNext
Loop
But I'm afraid that with my limited knowledge I have completely confused myself with trying to convert this to work on folder names.
This is where I have got so far -
strJobname = InputBox ("PLEASE ENTER THE JOB CODE")
Const adVarChar = 200
Const MaxCharacters = 255
Set DataList = CreateObject("ADOR.Recordset")
DataList.Fields.Append "FolderName", adVarChar, MaxCharacters
DataList.Fields.Append "FileDate", adVarChar, MaxCharacters
DataList.Open
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFol = objfso.getfolder("C:\Users\STUDIO 16\Desktop\BACKUP\ORIGINAL FOLDERS\")
set colSubfolders = objfol.subfolders
for each objsubfolder in colsubfolders
DataList.AddNew
DataList("FolderName") = objSubfolder.Name
'DataList("FileDate") = objFile.DateCreated
DataList.Update
Next
DataList.Sort = "FolderName"
DataList.MoveFirst
i = 1
Do Until DataList.EOF
If i < 10 Then
x = CStr("00" & i)
ElseIf i < 100 Then
x = CStr("0" & i)
ElseIf i < 1000 Then
x = CStr("" & i)
Else
x = i
End If
Newfoldername = "C:\Users\STUDIO 16\Desktop\BACKUP\ORIGINAL FOLDERS" & strJobname & "-" & x
objFSO.MoveFolder DataList.Fields.Item("FolderName"), Newfoldername
i = i + 1
DataList.MoveNext
Loop
I realise that there is probably no way that this was going to work as it is but it really has me stumped.
I know there are lots of batch renaming programs available but this is all part of a much bigger script that does other stuff so I would like to keep it all in one place. Plus, I don't like being stumped!
Any thoughts or help greatly appreciated!
Thanks.
I am trying to write script that will rename all folders in a subfolder. Currently the folders all have a time stamp name. 2013-10-07-14-22 for example. I am hoping to find a way to rename all these folders with a code given by the user and then a sequence number starting at 001.
For example - 130012-001
I know how to batch rename folders by replacing a known string with user input but it's replacing an unknown string with a value from user input plus a sequence number that is giving me trouble.
Using the script below I have been able to do this with all files within a folder -
strJobname = InputBox ("PLEASE ENTER THE JOB CODE")
Const adVarChar = 200
Const MaxCharacters = 255
Set DataList = CreateObject("ADOR.Recordset")
DataList.Fields.Append "FileName", adVarChar, MaxCharacters
DataList.Fields.Append "FileDate", adVarChar, MaxCharacters
DataList.Open
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\Users\STUDIO 16\Desktop\BACKUP\WEB JPEGS\")
Set colFiles = objFolder.Files
For Each objFile in colFiles
DataList.AddNew
DataList("FileName") = objFile.Path
'DataList("FileDate") = objFile.DateCreated
DataList.Update
Next
DataList.Sort = "FileName"
DataList.MoveFirst
i = 1
Do Until DataList.EOF
If i < 10 Then
x = CStr("00" & i)
ElseIf i < 100 Then
x = CStr("0" & i)
ElseIf i < 1000 Then
x = CStr("" & i)
Else
x = i
End If
strNewName = "C:\Users\STUDIO 16\Desktop\BACKUP\WEB JPEGS\" & ".jpg"
objFSO.MoveFile DataList.Fields.Item("FileName"), strNewName
i = i + 1
DataList.MoveNext
Loop
But I'm afraid that with my limited knowledge I have completely confused myself with trying to convert this to work on folder names.
This is where I have got so far -
strJobname = InputBox ("PLEASE ENTER THE JOB CODE")
Const adVarChar = 200
Const MaxCharacters = 255
Set DataList = CreateObject("ADOR.Recordset")
DataList.Fields.Append "FolderName", adVarChar, MaxCharacters
DataList.Fields.Append "FileDate", adVarChar, MaxCharacters
DataList.Open
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFol = objfso.getfolder("C:\Users\STUDIO 16\Desktop\BACKUP\ORIGINAL FOLDERS\")
set colSubfolders = objfol.subfolders
for each objsubfolder in colsubfolders
DataList.AddNew
DataList("FolderName") = objSubfolder.Name
'DataList("FileDate") = objFile.DateCreated
DataList.Update
Next
DataList.Sort = "FolderName"
DataList.MoveFirst
i = 1
Do Until DataList.EOF
If i < 10 Then
x = CStr("00" & i)
ElseIf i < 100 Then
x = CStr("0" & i)
ElseIf i < 1000 Then
x = CStr("" & i)
Else
x = i
End If
Newfoldername = "C:\Users\STUDIO 16\Desktop\BACKUP\ORIGINAL FOLDERS" & strJobname & "-" & x
objFSO.MoveFolder DataList.Fields.Item("FolderName"), Newfoldername
i = i + 1
DataList.MoveNext
Loop
I realise that there is probably no way that this was going to work as it is but it really has me stumped.
I know there are lots of batch renaming programs available but this is all part of a much bigger script that does other stuff so I would like to keep it all in one place. Plus, I don't like being stumped!
Any thoughts or help greatly appreciated!
Thanks.