
誰能教我如何使用批次檔僅取得檔案名稱?我需要建立一個循環來檢查它是否存在於另一個資料夾中,這樣我就不必複製。
答案1
在下面的FOR
循環中,您將獲得檔案名稱和副檔名:
for %%f in ("C:\Source\*") do ( echo File: %%~nxf )
若要檢查您的檔案是否存在於目標目錄中,如果不存在則複製:
for %%f in ("C:\Source\*") do (
if not exist "C:\Target\%%~nxf" (
echo Copy from source to target: %%~nxf
copy "%%f" "C:\Target\%%~nxf" )
)
有關更多FOR
循環參數,請參閱FOR /?
命令列。