[英]Any Tool/Trick to delete common files between 2 folders in Windows 7
我有2個文件夾,其內容幾乎相同,我希望做的是查找每個文件夾都不存在的文件
Folder 1: a.doc, b.doc, c.doc, d.doc
Folder 2: b.doc, d.doc, e.doc
由於每個文件夾都具有b.doc, d.doc
因此輸出將變為:
Folder 1: a.doc, c.doc
Folder 2: e.doc
Folder 1: a.doc, c.doc
(是的,它會自動將其刪除)
每個文件夾包含1000多個文件,其文件名均為韓文。
我目前正在做的是通過命令提示符通過dir獲取文件名列表,但實際上它只是手動。
請有人幫忙嗎?
這應該為您創建"c:\\file.bat.txt"
以便您在記事本中將其重命名為bat
並執行之前examine for accuracy
。
問題可能是Korean filenames
,因為批處理文件並不總是很好地處理非英語和Unicode字符。 可能需要更改代碼頁。
@echo off
for %%a in ("c:\folder1\*.*") do if exist "c:\folder2\%%~nxa" >"c:\file.bat.txt" echo del "%%a"
for %%a in ("c:\folder2\*.*") do if exist "c:\folder1\%%~nxa" >>"c:\file.bat.txt" echo del "%%a"
pause
這樣就可以完成工作,而不必處理韓文文件名。
警告此代碼刪除文件夾A和B之間的所有公用文件,僅考慮文件名。
@echo off
setlocal enableextensions disabledelayedexpansion
rem Target folders configuration
set "folderA=%cd%\a"
set "folderB=%cd%\b"
rem -----------------------------------------------------
rem Temporary work folders and output options
set "folderA1=%temp%\%~n0.a.%random%%random%%random%.tmp"
set "folderB1=%temp%\%~n0.b.%random%%random%%random%.tmp"
set "rcOpt=/njh /njs /np /nfl /ndl > nul"
rem Create a duplicate of the folders, with 0 bytes files
robocopy "%folderA%" "%folderA1%" /create %rcOpt%
robocopy "%folderB%" "%folderB1%" /create %rcOpt%
rem Remove all files in B1 present in A
rem Overwrites the files in A that will later be removed
robocopy "%folderB1%" "%folderA%" /xl /mov %rcOpt%
rem Remove all files in A1 present in B
rem Overwrites the files in B that will later be removed
robocopy "%folderA1%" "%folderB%" /xl /mov %rcOpt%
rem A1 contains only the non common files in A
rem B1 contains only the non common files in B
rem Delete from target folders the files not present in source
robocopy "%folderA1%" "%folderA%" /nocopy /purge %rcOpt%
robocopy "%folderB1%" "%folderB%" /nocopy /purge %rcOpt%
rem Cleanup
rmdir /s /q "%folderA1%" >nul 2>nul
rmdir /s /q "%folderB1%" >nul 2>nul
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.