我想只保留文件夹和子文件夹中同名文件的最新版本。换句话说,我想删除文件夹和子文件夹中的重复文件,仅考虑当两个文件具有相同的名称(和扩展名)时它们是重复的,并只保留具有最新修改日期的文件。
我知道我可以使用 CCleaner 或 Nirsoft 的 SearchMyFiles 等程序手动完成此操作,但它们无法选择除最新的文件之外的所有文件进行删除,您必须手动完成。
那么是否有一个命令行工具,或者cmd bat或powershell来完成这个任务?
答案1
我在这里为你制定了一个程序:https://github.com/ITCMD/Remove-Duplicates
DelDupe /?
输出:
Deletes duplicate Files except the latest edited.
DelDupe "Directory" "Filename" /F /C Character
Directory: Directory to search for duplicate names. Use C:\Users\IT Command\Documents\Batch Codes\Keep Recent Mod Date for current dir.
Filename: Duplicated Filename to search for
/F Do not prompt removal
/C Provide your own system character: The default character it uses to seperate files is ~. You don't need to know what this means, but if you have the ~ character in your filename then supply your own.
Character: The Character you want to use instead of ~
Example:
DelDupe "C:\Users\IT Command\Documents\Batch Codes\Keep Recent Mod Date" "Picture.png"
This example will surch all subdirectories in your current folder for a file called "Picture.png" and will delete all copies except for the most recently modified one.
Created by Lucas Elliott www.itcommand.tech
请注意,这不是一个要求人们为您制作完整脚本的网站。如果您不表明您已经尝试过,人们会生气(我知道您可能不知道从哪里开始)。在我看来,像您这样提问是可以的,但不要总是期待完整的答案。无论如何,我只是需要这个。