我正在制作一个简单的AppleScript,用于复制SD卡以备份到我的本地磁盘上。文件夹的复制和重命名似乎很顺利,当我发现检查一切似乎是好的,但我也试图在脚本中创建一个小的完整性检查,以确保一切正确复制,但它总是返回源上的另外一个文件最终会在目标文件夹中。
所有内容似乎都能从我所知道的内容中正确复制,但为什么这些文件数量不同?
global master_folder, final_destination
set the master_folder to "Macintosh HD:Users:jeremy:Desktop:Test Media Folder:"
set the source_folder to (choose folder with prompt "Select the folder that will contain the files to copy:")
set the dayOfSession to (choose from list {"Thursday", "Friday", "Saturday", "Sunday"} with prompt "Day of Session:") as text
set the timeOfSession to (choose from list {"Morning", "Afternoon", "Night", "Other"} with prompt "Session") as text
set the camera to (choose from list {"100", "200", "300", "400", "500", "600", "700"} with prompt "Day of Session:") as text
set the final_destination to my determine_Foldername(dayOfSession, timeOfSession, camera)
tell application "Finder"
set destination to duplicate source_folder to master_folder
set name of destination to final_destination
end tell
my check_integrity(source_folder, master_folder & final_destination)
on check_integrity(source, destination)
set warnings to 0
set numberOfSourceFiles to my file_count(source)
set numberOfDestinationFiles to my file_count(destination)
if not (numberOfSourceFiles = numberOfDestinationFiles) then
set warnings to warnings + 1
display dialog "It does not appear that all the files copied over." with title "UH-OH!"
end if
if warnings = 0 then
display dialog "Everything seems to have gone as planned." with title "All done!"
end if
end check_integrity
on file_count(theFolder)
return (do shell script "find " & quoted form of POSIX path of theFolder & " \\! -name '.*' | wc -l") as integer
end file_count
on determine_Foldername(day, time, camera)
if (day = "Thursday") then
set day to "0828"
else if (day = "Friday") then
set day to "0829"
else if (day = "Saturday") then
set day to "0830"
else if (day = "Sunday") then
set day to "0831"
end if
if (time = "Morning") then
set time to "0900"
else if (time = "Afternoon") then
set time to "1300"
else if (time = "Night") then
set time to "1830"
else if (time = "Other") then
set time to "2400"
end if
set the card to 1
repeat
set folder_name to "DT-" & day & "-" & time & "." & (camera + card)
tell application "Finder"
if not (exists master_folder & folder_name) then
exit repeat
end if
end tell
set the card to card + 1
end repeat
return folder_name
end determine_Foldername
答案 0 :(得分:0)
因为我在整个驱动器上重复,所以.Trashes
正在计算find
个duplicate
文件夹,但on file_count(theFolder)
return (do shell script "find " & quoted form of POSIX path of theFolder & " \\( ! -regex '.*/\\..*' \\) | wc -l") as integer
end file_count
没有发送过来。我决定只计算所有不以句点开头的文件/文件夹。所以我的文件柜台现在看起来像这样......
{{1}}