不确定是否有人可以帮助我。 如何搜索特定位置/目录中是否存在特定文件?
检查“mydatetime_computername.zip”是否在磁盘d:\ asd中退出 如果是,请删除c:\ mydatetime_computername.zip中的文件 否则拉链并再次复制。
@echo off
net use L: /delete /y
goto 1
:1
net use L: \\129.101.115.1\d$\triagelog grl@lock /user:testadmin /persistent:yes
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
7za a -tzip "c:\%computername%-%mydate%.zip" "c:\temp"
move C:\%computername%-%mydate%.zip *.* L:\Triagelog
for /r L:\Triagelog %%a in (*) do if "%%~nxa"=="%computername%-%mydate%.zip" set p=%%~dpnxa
if defined p (
echo %p%
::rmdir /f/q "C:\temp"
del /f/q "C:\temp"
echo File deleted.
) else (
echo Fail to search file..
)
答案 0 :(得分:0)
要检查文件是否存在,请使用if exist [path\]<filename>
if exist "d:\asd\mydatetime_computername.zip" (
del "c:\mydatetime_computername.zip"
) else (
echo does not exist...
)