I have roughly a thousand files in 40 folders, many of which have the same name. The folders are named with dates (YYYY-MM-DD), and the files are named with times (HH_mm_ss). Most of the files end ...0_00 as they were created at 10-minute intervals. Do any of you know how I can rename them all to include the name of the folder they're in? Am thinking that it would probably be a doddle in *nix, but alas...
This is in Windows, so no particular language. I *could* copy them all to my *nix web server and do some CLI stuff, but I wouldn't know what. Are there any apps to do things like this?
You still looking to do something.. I have written several vbscripts files that does something similar. Let me know and I can whip something up for you real quick, otherwise not sure if there is a GUI program or not.
Here you go. Just copy and paste in a .vbs file and change TEMPLOGFILE, DATETIMESEPERATOR (if you want), and showFolderList(<your folder>). Code: Option Explicit Dim oFS, fso, f, f2, subFolder, subFiles CONST DEBUG_MODE = 1 ' NOTE: Change the below 2 lines if you need to CONST DATETIMESEPERATOR = "-" CONST TEMPLOGFILE = "D:\Projects\Rename File Script\RenameFileScript.log" ' NOTE: Folder should be the parent folder to which the subfolders are the dates showfolderlist("D:\Projects\Rename File Script\") msgbox "done" Function ShowFolderList(folderspec) Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.GetFolder(folderspec) ' Loop through subFolders and their associated files For Each subFolder in f.SubFolders For Each subFiles in subFolder.files ' Calling renameFile Sub Routine renameFiles subFiles Next Next Set f = Nothing Set fso = Nothing End Function Sub renameFiles(objFile) Set oFS = WScript.CreateObject("Scripting.FileSystemObject") DebugPrint "ojbFile.path = " & objFile.path oFS.MoveFile objFile.path, objFile.ParentFolder & "\" & objFile.ParentFolder.Name & DATETIMESEPERATOR & objFile.name Set oFS = nothing End Sub Sub DebugPrint(strMessage) If (DEBUG_MODE XOr 1) = (DEBUG_MODE - 1) Then LogToFile strMessage End If If (DEBUG_MODE XOr 2) = (DEBUG_MODE - 2) Then MsgBox strMessage End If End Sub Sub LogToFile(strMessage) Dim objFSO, objTStream On Error Resume Next Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTStream = objFSO.OpenTextFile(TEMPLOGFILE, 8, True) Call objTStream.WriteLine(Now & ": " & strMessage) objTStream.Close Err.Clear End Sub
Looks great, but unfortunately it doesn't work. log file: Code: 2006-05-08 17:04:44: ojbFile.path = D:\My Pictures\Webcam\_keep\C\2006-01-09\2006-01-09-2006-01-09-2006-01-09-2006-01-09-2006-01-09-2006-01-09-2006-01-09-2006-01-09-2006-01-09-2006-01-09-2006-01-09-2006-01-09-2006-01-09-2006-01-09-2006-01-09-2006-01-09-2006-01-09-2006-01-09-10_22_53.jpg PS - I don't know if it matters, but the date is separated by '-', and the times by '_'.
What did you put as the folder path? Make sure it is includes the final "\" after the folder. So it should be "D:\My Pictures\Webcam\_keep\C\" or "D:\My Pictures\Webcam\_keep\C\2006-01-09\" Also, can you give me an idea about how you have the directory structure setup? I tested it here, but may have setup the structure differently. I used "C:\Projects\Test\" as my folder. Mine was: C:\Projects\Test\ C:\Projects\Test\2006-05-25\ C:\Projects\Test\2006-05-25\06_30_00.jpg C:\Projects\Test\2006-05-25\06_20_00.jpg C:\Projects\Test\2006-05-24\ C:\Projects\Test\2006-05-24\06_30_00.jpg C:\Projects\Test\2006-05-24\06_20_00.jpg
It wouldn't work for the parent folder (C), and when I tried it with a folder, the first file was named "2006-01-09-2006-01-09-...-2006-01-09-2006-01-09-2006-01-09-2006-01-09-10_22_53.jpg" ! PS, using the parent folder results in the error 'path not found' on line 35.
showfolderlist("D:\my pictures\Webcam\_keep\C\") [hmm, just thought - is it anything to do with the '_' in '_keep'? nope, just tried it somewhere else]
Have you tried, it worked for me when i was doing batch renaming http://www.freewarebox.com/free_3313_the-rename-download.html
Can you do a print screen of your folder structure? I do not think I totally understand how you have it setup and I am making some assumptions that might be causing problems. In addition, are all the HH_MM_SS.jpg using 2-digits? example: 02_03_00.jpg?
Atomic: thanks, that worked - though it's not the most intuitive program! Coeus: thanks for trying, am sure it was really close. If you want to keep trying (out of curiosity or whatever) then I'll help.
Nah its not great, I cant remember the name of the better version i found after as ive uninstalled it now..