I have a folder on a volume on a file server that contains a number of files inside a moderately complex hierarchy of folders. I need to copy all of these files from their current location to a new location on a different file server, and the files need to be renamed as they move. Here’s what I have now:
SOURCE DRIVE
-Folder 1
-Folder A
-Image 1.jpg
-Image 2.jpg
-Image 3.jpg
-Folder B
-Image 1.jpg
-Image 2.jpg
-Folder 2
-Folder C
-Image 1.jpg
-Image 2.jpg
-Image 3.jpg
-Image 4.jpg
On my DESTINATION DRIVE I manually created Folder 1, Folder 2, etc.
DESTINATION DRIVE
-Folder 1
-Folder 2
-Folder 3
I also have a text file that contains the exact locations of each file on the SOURCE DRIVE, the path to a folder that the image needs to be copied into on the DESTINATION DRIVE, and the new name of each file. It’s arranged on a line-by-line basis, as such:
NAME OF THE FOLDER TO COPY INTO ON DESTINATION DRIVE
COMPLETE PATH TO FILE ON SOURCE DRIVE
COMPLETE PATH TO FILE ON DESTINATION DRIVE
NAME OF THE FOLDER TO COPY INTO ON DESTINATION DRIVE
COMPLETE PATH TO FILE ON SOURCE DRIVE
COMPLETE PATH TO FILE ON DESTINATION DRIVE
NAME OF THE FOLDER TO COPY INTO ON DESTINATION DRIVE
COMPLETE PATH TO FILE ON SOURCE DRIVE
COMPLETE PATH TO FILE ON DESTINATION DRIVE
EOF
The “EOF” designates the end of the file, natch. My script reads the file into a variable then sets three counters (folderCounter, sourceCounter, and destCounter) to identify the locations of three lines in my text file. Line 1 of my text file is the destination folder path (artistFolder), line 2 of my text file is the complete path to the source file (sourceFile), and line 3 of my text file is the complete path (including new file name) to the destination file (destFile).
Before doing anything it checks to see if artistFolder contains “EOF” and if so, it exits the script (since that would indicate that everything has been copied).
It then checks to see if the destination folder exists, and if not, it creates one. It then copies the file from the source to the destination. As each iteration of the loop occurs 3 is added to each value of folderCounter, sourceCounter, and destCounter. So the first time it goes through lines 1, 2, and 3, then the next time it’s 4, 5, and 6, then 7, 8, and 9, etc.
Problem is, it’s not working. When I disable the loop (so it only runs once, theoretically only copying one file) no copy is made, and I get a result of “6”.
I know I’m doing something elementary-wrong but I can’t see it. Any help would be appreciated.
on run
set theFile to (choose file with prompt "Select a file to read:" of type {"TEXT"})
open for access theFile
set fileContents to (read theFile)
close access theFile
set folderCounter to 1
set sourceCounter to 2
set destCounter to 3
repeat
set artistFolder to paragraph folderCounter of fileContents
if artistFolder = "EOF" then
beep
exit repeat
end if
set sourceFile to paragraph sourceCounter of fileContents
set destFile to paragraph destCounter of fileContents
tell application "Finder"
if exists artistFolder is false then
make new folder with properties {artistFolder}
end if
copy sourceFile to destFile
end tell
set artistFolder to folderCounter + 3
set sourceCounter to sourceCounter + 3
set destCounter to destCounter + 3
end repeat
end run