花了一些時間,但我自己找到了答案。如果將來對任何人有用,請發佈此信息。
dir "%~dp0PlaceShortcutsHere\*" /a /b /-p /o:gen>>"%~dp0ShortcutList_%date:~-4,4%%date:~-7,2%%date:~-10,2%.txt"
Pushd \\<Server>\<Share>
for /F "delims=" %%G in (ShortcutList_%date:~-4,4%%date:~-7,2%%date:~-10,2%.txt) DO Del "C:\Users\Public\Desktop\%%G"
del "%~dp0ShortcutList_%date:~-4,4%%date:~-7,2%%date:~-10,2%.txt"
其分解:
dir "%~dp0PlaceShortcutsHere\*" /a /b /-p /o:gen>>"%~dp0ShortcutList_%date:~-4,4%%date:~-7,2%%date:~-10,2%.txt"
上面創建的,在它的快捷方式的名稱的文本文件,由下一行引用。
Pushd \\<Server>\<Share>
for /F "delims=" %%G in (ShortcutList_%date:~-4,4%%date:~-7,2%%date:~-10,2%.txt) DO Del "C:\Users\Public\Desktop\%%G"
上述映射服務器/股,該文件是暫時,然後使用「FOR/F」循環獲取文件名,然後刪除它們。
del "%~dp0ShortcutList_%date:~-4,4%%date:~-7,2%%date:~-10,2%.txt"
最後,這行刪除了創建的文本文件。
當文件夾內容不斷變化時,它會很有用,它會創建一個最新的文件列表,然後再刪除列表,避免混淆。
%date:~-4,4%%date:~-7,2%%date:~-10,2%
最後,這個小行會輸入當前日期到文本documet的文件名,所以應該最後刪除行不行,你可以看到它的日期。在猜測中,我也會認爲將它放在路徑中會使腳本只選擇當天的文件,而不是其他任何文件,但我沒有測試過。
請糾正我,如果我在任何錯誤。