我在文件夹A中有一些重要的文件,然后我将它们备份到另一个驱动器上的文件夹B中。
FOLDER A: Filename01. Filename02. Filename03. ...
FOLDER B: Filename01. Filename02. Filename03. ...
然后,我将文件夹B中的Filename02重命名为Filename02new。
FOLDER A: Filename01. Filename02. Filename03. ...
FOLDER B: Filename01. Filename02new. Filename03. ...
现在我想同步这两个文件夹。将文件夹A中的Filename02更改为Filename02new。如果在这两个文件夹中有许多相同的文件具有不同的文件名,有没有一种快速的方法,自动的方法,或者任何软件都可以完成这项工作-在不同的文件夹中找到具有不同文件名的副本,然后同步它们的文件名?
发布于 2021-06-16 20:01:03
set folderA to choose folder -- alias
set folderB to choose folder -- alias
tell application "Finder"
repeat with i from 1 to count (items of folderA)
set aItem to item i of folderA
set aSize to size of aItem
set posix_Path_1 to quoted form of (POSIX path of (aItem as text))
repeat with j from 1 to count (items of folderB)
set bItem to item j of folderB
set bSize to size of bItem
if aSize = bSize then -- if size is same, than items can be duplicates
set posix_Path_2 to quoted form of (POSIX path of (bItem as text))
-- compare items further
set shell_Command_String to "cmp -s" & posix_Path_1 & space & posix_Path_2
set exitStatus to 0 -- setting initial status of shell operation
try
set exitStatus to do shell script shell_Command_String
return exitStatus
end try
if exitStatus = 0 then -- if exitStatus remains= 0, that indicates "files is same"
set name of aItem to name of bItem
exit repeat
end if
end if
end repeat
end repeat
end tell
发布于 2021-06-17 22:45:37
我不能编辑Robert的代码,所以我在这里发布了编辑后的代码:
set folderA to choose folder
set folderB to choose folder
tell application "Finder"
set numberA to count files of entire contents of folderA
set numberB to count files of entire contents of folderB
repeat with i from 1 to numberA
set aItem to item i of folderA
set aSize to size of aItem
set posix_Path_1 to quoted form of (POSIX path of (aItem as text))
repeat with j from 1 to numberB
set bItem to item j of folderB
set bSize to size of bItem
if aSize = bSize then
set posix_Path_2 to quoted form of (POSIX path of (bItem as text))
set shell_Command_String to "cmp " & posix_Path_1 & space & posix_Path_2
set exitStatus to 0
try
set exitStatus to do shell script shell_Command_String
end try
if exitStatus ≠ 0 then
set name of aItem to name of bItem
exit repeat
end if
end if
end repeat
end repeat
end tell
https://stackoverflow.com/questions/67963552
复制相似问题