AutoHotkey Community

It is currently May 27th, 2012, 5:37 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: March 14th, 2010, 2:47 pm 
Offline

Joined: May 8th, 2008, 2:29 am
Posts: 6
Location: Middle River,MD
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. :?




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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2010, 3:14 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
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! <--


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2010, 3:35 pm 
Offline

Joined: May 8th, 2008, 2:29 am
Posts: 6
Location: Middle River,MD
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:
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? :(


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2010, 4:06 pm 
Offline

Joined: May 8th, 2008, 2:29 am
Posts: 6
Location: Middle River,MD
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2010, 4:21 pm 
Offline

Joined: May 8th, 2008, 2:29 am
Posts: 6
Location: Middle River,MD
Still need some help-Pleaseeeeeeeeeeeeeeeeee!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2010, 5:06 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
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! <--


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2010, 6:54 pm 
Offline

Joined: May 8th, 2008, 2:29 am
Posts: 6
Location: Middle River,MD
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2010, 7:48 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
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.

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

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

_________________
{1:"ahkstdlib", 2:"my libs", 3:"my apps", 4:"my license"}
--> Don't feed the troll! <--


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], HotkeyStick, mrhobbeys, rbrtryn and 61 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group