在不同文件夹中查找具有不同文件名的重复文件,同步它们的文件名
find duplicate files with different filenames in different folders, sync their filenames
我在文件夹 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. ...
现在我想同步这两个文件夹。将 FOLDER A 中的 Filename02 更改为 Filename02new。
如果这两个文件夹中有很多相同的文件但文件名不同,有没有快速的方法,自动的方法,或者任何软件都可以完成这项工作 - 在不同的文件夹中找到具有不同文件名的重复文件,然后同步它们的文件名?
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 的代码,所以我 post 在此处编辑了代码:
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
我在文件夹 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. ...
现在我想同步这两个文件夹。将 FOLDER A 中的 Filename02 更改为 Filename02new。 如果这两个文件夹中有很多相同的文件但文件名不同,有没有快速的方法,自动的方法,或者任何软件都可以完成这项工作 - 在不同的文件夹中找到具有不同文件名的重复文件,然后同步它们的文件名?
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 的代码,所以我 post 在此处编辑了代码:
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