在不同的文件夹中找到具有不同文件名的重复文件,同步它们的文件名



我在FOLDER A中有一些重要文件,然后将它们备份到不同驱动器上的FOLDER B中。

FOLDER A:   Filename01. Filename02. Filename03. ...
FOLDER B:   Filename01. Filename02. Filename03. ...

然后我将文件夹B中的文件名02重命名为文件名02new。

FOLDER A:   Filename01. Filename02. Filename03. ...
FOLDER B:   Filename01. Filename02new. Filename03. ...

现在我想同步这两个文件夹。将文件夹A中的文件名02更改为文件名02new。如果这两个文件夹中有许多相同的文件具有不同的文件名,有没有一种快速、自动或任何软件可以完成这项工作——在不同的文件夹中找到具有不同文件名的重复文件,然后同步它们的文件名?

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

我无法编辑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

相关内容

  • 没有找到相关文章

最新更新