我想写一个批处理脚本,我双击它,它应该将文件从一个目录复制到另一个目录并重命名为fileX,知道目标目录中有一个同名的文件。
所以我想要做的是删除已经存在的fileX并复制另一个。
我该怎么做,请对脚本发表评论,以便我理解。
答案 0 :(得分:0)
您可以使用命令xcopy
来执行此操作。例如:
echo [Copy files]
echo * Create the file xcopy_EXCLUDE.txt in order to ignore some file and/or directory.
echo .au3 > xcopy_Exclude.txt
echo .pspimage >> xcopy_Exclude.txt
echo \psp\ >> xcopy_Exclude.txt
echo * - ignore all .au3 files
echo * - ignore all .pspimage files
echo * - ignore the \psp\ directory
echo * The file xcopy_EXCLUDE.txt is created.
echo.
echo * Copy additional files with xcopy.
xcopy "%FOLDER_SRC%" "%FOLDER_OUT%" /E /H /Y /EXCLUDE:xcopy_Exclude.txt
echo * Files and directory are copied.
echo.
echo * Delete xcopy_Exclude.txt.
del xcopy_Exclude.txt
答案 1 :(得分:0)
如果你愿意研究powershell。这是你要运行的命令。
# Path is the location to the original file
# Destination is where you want it to go
# -force indicates that it shoud replace a file if it finds it and not prompt you first
Copy-Item -Path "c:\temp\original.txt" -Destination "c:\folder2\filex.txt" -force
# For more help:
Get-Help Copy-Item