AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Renaming files from a given list

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
jdrasal



Joined: 08 May 2008
Posts: 6
Location: Middle River,MD

PostPosted: Sun Mar 14, 2010 1:47 pm    Post subject: Renaming files from a given list Reply with quote

Hi All
I did'nt want to ask but............... , I have been working on this for three weeks and I am totaly stumped. I have read the help files and am starting to get a great understanding but I think in this case it's more of the way to go about it. And any help would greatly be appreciated!!

I have a csv file list with up to 200 lines: C:\Docs\DatabaseExport.csv

    220011001,jane doe
    220011002,john doe


Then I have a folder with photos in it up to 20,000:C\Docs\Folder2

    220011001.jpg
    220011002.jpg



I want to rename the photo files with the matching line of the text file:
Example: 220011001.jpg to 220011001,jane doe.jpg


first I copied the photos that match the list given in to Folder3 :notice that the text files start with the name of the photo , i get the file reading and looping and have that in the code already but I cant seem to figure out how to rename the file with the string from the csv file.

Here is what I have and please excuse the commented out parts but I 've been trying everything. Confused




Code:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
File1 := "C:\Docs\DatabaseExport.csv"
Folder2 := "C:\Docs\Folder2"
Folder3 := "C:\Docs\Folder3"
    Loop, Read, %File1%
   {
    IfExist, %Folder2%\%A_LoopFilename%
    FileCopy , %Folder2%\%A_LoopFilename% , C:\Docs\Folder3 ,1
   Break
   }

FileRead, File1 , %File1%

     
Loop, Parse, File1, `n, `r
{
    DbFileName:= A_LoopField
   
   MsgBox , 4 , , this is in text file %DbFileName%
    IfMsgBox , No
   Return
    Loop , C:\Docs\Folder3\*.* , 0
    {
        MsgBox , 4 , , the filename is %DbFileName%
        Folder3_FileName = %A_LoopFileName%
      MsgBox , 4 , , thats the filename is %Folder3_FileName%
      StringTrimLeft , New_Folder3_FileName , Folder3_FileName , 9
      ;If DbFileName Contains %Folder3_FileName%
      ;ListVars
      StringReplace , New_Name , New_Folder3_FileName , %New_Folder3_FileName% , %DbFileName% , All
      ListVars
      
      
      
    }
   
         
      
       
}
Back to top
View user's profile Send private message Send e-mail
Tuncay



Joined: 07 Nov 2006
Posts: 1886
Location: Germany

PostPosted: Sun Mar 14, 2010 2:14 pm    Post subject: Reply with quote

Hope this helps:
Code:
#NoEnv
#SingleInstance force
SetWorkingDir %A_ScriptDir%
SetBatchLines, -1 ; At end of init set to 0.

; Settings
csv_file := "C:\Docs\DatabaseExport.csv"    ; Database with the new file names.
source_folder := "C\Docs\Folder2"           ; Place of the source photos.
destination_folder := "C:\Docs\Folder3"     ; Where to copy the files.

; CSV file content is expected like this:
/*
220011001,jane doe
220011002,john doe
*/

; File names in source folder are expected like this:
/*
220011001.jpg
220011002.jpg
*/

; Processing
FileCreateDir, %destination_folder%
Loop, Read, %csv_file%
{
    ; A_LoopReadLine contains in example "220011001,jane doe".
    Loop, Parse, %A_LoopReadLine%, CSV
    {
        ; If A_Index is "1", then A_LoopField contains in example "220011001".
        FileCopy, %source_folder%\%A_LoopField%.jpg, %destination_folder%\%A_LoopReadLine%.jpg, 1
        Continue ; First entry is needed, not more.
    }
}

Untested!
_________________
{1:"ahkstdlib", 2:"my libs", 3:"my apps", 4:"my license"}
--> Don't feed the troll! <--
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jdrasal



Joined: 08 May 2008
Posts: 6
Location: Middle River,MD

PostPosted: Sun Mar 14, 2010 2:35 pm    Post subject: Reply with quote

Hi
I appreciate you getting back so quickly but still no luck,dosent seem to copy the files ,it creates the folder but not the files . Crying or Very sad
I got an error @ the line:
Code:

Loop, Parse, %A_LoopReadLine%, CSV


But i changed it to:
Code:

Loop, Parse, A_LoopReadLine, CSV


If thats right but still not copying and renaming to folder.
Any other possibilities? Sad
Back to top
View user's profile Send private message Send e-mail
jdrasal



Joined: 08 May 2008
Posts: 6
Location: Middle River,MD

PostPosted: Sun Mar 14, 2010 3:06 pm    Post subject: Reply with quote

I also notice that it is reading the same info in the A_LoopField Variable it is stepping through the line of info from the text file
Back to top
View user's profile Send private message Send e-mail
jdrasal



Joined: 08 May 2008
Posts: 6
Location: Middle River,MD

PostPosted: Sun Mar 14, 2010 3:21 pm    Post subject: Reply with quote

Still need some help-Pleaseeeeeeeeeeeeeeeeee!
Back to top
View user's profile Send private message Send e-mail
Tuncay



Joined: 07 Nov 2006
Posts: 1886
Location: Germany

PostPosted: Sun Mar 14, 2010 4:06 pm    Post subject: Reply with quote

sorry there where typo(s). Try that script, with manually selection of folders and file. Make sure the folder contains all photos. You do not preselect them.

Code:
#NoEnv
#SingleInstance
SetWorkingDir %A_ScriptDir%
SetBatchLines, -1 ; At end of init set to 0.

; Settings
csv_file := "C:\Docs\DatabaseExport.csv"    ; Database with the new file names.
source_folder := "C:\Docs\Folder2"           ; Place of the source photos.
destination_folder := "C:\Docs\Folder3"     ; Where to copy the files.

; CSV file content is expected like this:
/*
220011001,jane doe
220011002,john doe
*/

; File names in source folder are expected like this:
/*
220011001.jpg
220011002.jpg
*/

; Setup Folders
FileSelectFile, csv_file, , %csv_file%, Which file contains the names?, CSV files (*.csv)
FileSelectFolder, source_folder, %source_folder%, 1, Where are the photos?
FileSelectFolder, destination_folder, %destination_folder%, 1, Where to copy the files?
FileCreateDir, %destination_folder%

; Processing
Loop, Read, %csv_file%
{
    line := A_LoopReadLine
    ; A_LoopReadLine contains in example "220011001,jane doe".
    Loop, Parse, line, CSV
    {
        ; If A_Index is "1", then A_LoopField contains in example "220011001".
        FileCopy, %source_folder%\%A_LoopField%.jpg, %destination_folder%\%line%.jpg, 1
        Break ; First entry is needed, not more.
    }
}

Still untested, because i do not have your files. And if any error message is distplayed, then show what is say.
_________________
{1:"ahkstdlib", 2:"my libs", 3:"my apps", 4:"my license"}
--> Don't feed the troll! <--
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jdrasal



Joined: 08 May 2008
Posts: 6
Location: Middle River,MD

PostPosted: Sun Mar 14, 2010 5:54 pm    Post subject: Reply with quote

Thank You sooooooooooooooooooo much,I appreciate your time and patience. I just wish I could of figured this out myself but again I was going the wrong, long way about it. This will help me learn though. If ever I could find a way to repay you I will! I really appreciate this you are so helpful.
Have a great day!!!!!!!!! Very Happy Very Happy Very Happy Very Happy
Back to top
View user's profile Send private message Send e-mail
Tuncay



Joined: 07 Nov 2006
Posts: 1886
Location: Germany

PostPosted: Sun Mar 14, 2010 6:48 pm    Post subject: Reply with quote

Hehe. Cool I am glad it helped you and that it works. Just learn about Ahk by reading and studieng and helping others. Thats all.

I had some time and that script did took just some minutes to write. And I love those people who helped me as i asked when I was a beginner here. I know how hard it is.

Quote:
Have a great day!!!!!!!!!

Thx and thx for your nice words. I wish you a good day also. bye until next time. Smile
_________________
{1:"ahkstdlib", 2:"my libs", 3:"my apps", 4:"my license"}
--> Don't feed the troll! <--
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group