我正在编写这个批处理脚本,但是当它查看文件扩展名的所有文件是否存在时,它会继续执行,甚至是文件存在的其他文件。感谢您的帮助!
@echo off
if not exist C:\Users\%USERNAME%\Desktop\workBackup (
::creates new folder 'workBackup'
mkdir C:\Users\%USERNAME%\Desktop\workBackup
)
set TIMESTAMP=%DATE:~4,2%%DATE:~7,2%%DATE:~10,4%
if not exist C:\Users\%USERNAME%\Desktop\workBackup\%TIMESTAMP% (
::creates new folder to put work into
mkdir C:\Users\%USERNAME%\Desktop\workBackup\%TIMESTAMP%
)
if not exist C:\Users\%USERNAME%\Desktop\workBackup\%TIMESTAMP%\logs (
::creates logs folder
mkdir C:\Users\%USERNAME%\Desktop\workBackup\%TIMESTAMP%\logs
)
if exist C:\User\%USERNAME%\Documents\workspace\out\log\*.xlsx (
::moves all xlsx files to workBackup folder
move "C:\User\%USERNAME%\Documents\workspace\out\log\"*.xlsx C:\Users\%USERNAME%\Desktop\workBackup\%TIMESTAMP%\
) else (
::exits if file no files are found
echo "Files not found"
exit /b
)
if exist C:\User\%USERNAME%\Documents\workspace\out\log\*.xlsx (
::moves all log files to workBackup folder
move "C:\Users\%USERNAME%\Documents\workspace\out\log\"*.log C:\Users\%USERNAME%\Desktop\workBackup\%TIMESTAMP%\logs
) else (
::exits if file no files are found
echo "Files not found"
exit /b
)
答案 0 :(得分:0)
有几件事需要提及
@echo off
for /f %%A in ('wmic os get LocalDateTime^|findstr ^^[0-9]') do Set _DT=%%A
Set yy=%_DT:~0,4%&Set MM=%_DT:~4,2%&Set dd=%_DT:~6,2%
Set "WBu=C:\Users\%USERNAME%\Desktop\workBackup"
Set "WBuDT=%WBu%\%dd%%MM%%yy%"
:: or reverse day and month %MM%%dd%%yy%
Set "WSpOL=C:\Users\%USERNAME%\Documents\workspace\out\log"
mkdir "%WBuDT%\logs" 2>NUL
::moves all xlsx files to workBackup folder
move "%WSpOL%\*.xlsx" "%WBuDT%\" 2>NUL||(Echo "%WSpOL%\*.xlsx" not found&Exit /b)
::moves all log files to workBackup folder
move "%WSpOL%\*.log" "%WBuDT%\logs\" 2>NUL||(Echo "%WSpOL%\*.log" not found&Exit /b)