Development rename file using folder name?

Discussion in 'Software' started by jezmck, 5 May 2006.

  1. jezmck

    jezmck Minimodder

    Joined:
    25 Sep 2003
    Posts:
    4,456
    Likes Received:
    36
    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...
     
  2. Coeus

    Coeus What's a Dremel?

    Joined:
    14 Oct 2003
    Posts:
    13
    Likes Received:
    0
    What OS are you running and are you looking for any specific language?
     
  3. jezmck

    jezmck Minimodder

    Joined:
    25 Sep 2003
    Posts:
    4,456
    Likes Received:
    36
    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?
     
  4. Coeus

    Coeus What's a Dremel?

    Joined:
    14 Oct 2003
    Posts:
    13
    Likes Received:
    0
    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.
     
  5. jezmck

    jezmck Minimodder

    Joined:
    25 Sep 2003
    Posts:
    4,456
    Likes Received:
    36
    I still need someway of doing it, so if you can help it will be much appreciated.
     
  6. Coeus

    Coeus What's a Dremel?

    Joined:
    14 Oct 2003
    Posts:
    13
    Likes Received:
    0
    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
     
  7. jezmck

    jezmck Minimodder

    Joined:
    25 Sep 2003
    Posts:
    4,456
    Likes Received:
    36
    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 '_'.
     
  8. Coeus

    Coeus What's a Dremel?

    Joined:
    14 Oct 2003
    Posts:
    13
    Likes Received:
    0
    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
     
  9. jezmck

    jezmck Minimodder

    Joined:
    25 Sep 2003
    Posts:
    4,456
    Likes Received:
    36
    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.
     
  10. Coeus

    Coeus What's a Dremel?

    Joined:
    14 Oct 2003
    Posts:
    13
    Likes Received:
    0
    Please paste your [showfolderlist("D:\Projects\Rename File Script\")] line from your text file
     
  11. jezmck

    jezmck Minimodder

    Joined:
    25 Sep 2003
    Posts:
    4,456
    Likes Received:
    36
    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]
     
  12. Atomic

    Atomic Gerwaff

    Joined:
    6 May 2002
    Posts:
    9,646
    Likes Received:
    94
  13. Coeus

    Coeus What's a Dremel?

    Joined:
    14 Oct 2003
    Posts:
    13
    Likes Received:
    0
    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?
     
  14. Coeus

    Coeus What's a Dremel?

    Joined:
    14 Oct 2003
    Posts:
    13
    Likes Received:
    0
    Might want to try that other program, if you want too, either way is fine by me
     
  15. jezmck

    jezmck Minimodder

    Joined:
    25 Sep 2003
    Posts:
    4,456
    Likes Received:
    36
    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.
     
  16. Atomic

    Atomic Gerwaff

    Joined:
    6 May 2002
    Posts:
    9,646
    Likes Received:
    94
    Nah its not great, I cant remember the name of the better version i found after as ive uninstalled it now..
     
  17. Coeus

    Coeus What's a Dremel?

    Joined:
    14 Oct 2003
    Posts:
    13
    Likes Received:
    0
    No pro.

    No need to keep trying. Glad you found something that works.
     

Share This Page