Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Renaming files from a given list


  • Please log in to reply
7 replies to this topic
joed3isme
  • Members
  • 6 posts
  • Last active: Mar 11 2015 01:45 AM
  • Joined: 08 May 2008
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. :?




#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
		
		
	   
	 }
	
         
		
       
}


Tuncay
  • Members
  • 1945 posts
  • Last active: Feb 08 2015 03:49 PM
  • Joined: 07 Nov 2006
Hope this helps:
#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!

No signature.


joed3isme
  • Members
  • 6 posts
  • Last active: Mar 11 2015 01:45 AM
  • Joined: 08 May 2008
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 . :cry:
I got an error @ the line:
Loop, Parse, %A_LoopReadLine%, CSV

But i changed it to:
Loop, Parse, A_LoopReadLine, CSV

If thats right but still not copying and renaming to folder.
Any other possibilities? :(

joed3isme
  • Members
  • 6 posts
  • Last active: Mar 11 2015 01:45 AM
  • Joined: 08 May 2008
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

joed3isme
  • Members
  • 6 posts
  • Last active: Mar 11 2015 01:45 AM
  • Joined: 08 May 2008
Still need some help-Pleaseeeeeeeeeeeeeeeeee!

Tuncay
  • Members
  • 1945 posts
  • Last active: Feb 08 2015 03:49 PM
  • Joined: 07 Nov 2006
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.

#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.

No signature.


joed3isme
  • Members
  • 6 posts
  • Last active: Mar 11 2015 01:45 AM
  • Joined: 08 May 2008
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!!!!!!!!! :D :D :D :D

Tuncay
  • Members
  • 1945 posts
  • Last active: Feb 08 2015 03:49 PM
  • Joined: 07 Nov 2006
Hehe. 8) 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.

Have a great day!!!!!!!!!

Thx and thx for your nice words. I wish you a good day also. bye until next time. :)

No signature.