我在我的BATCH FILE的开头做了如下目录来存储临时内容。
"%userprofile%/Downloads/VersionCheckWillDelete"
我想删除这个文件夹及其所有内容。
下面只删除文件夹中的数据,但不删除文件夹本身。
RD /S /Q "%userprofile%\Downloads\VersionCheckWillDelete"
EDIT: 结果发现并没有删除它 因为BATCH文件还在使用它。我考虑过POWERSHELL还在打开,想把它杀掉,但它没有打开。我怎么在后台关闭它。它不需要再运行了吗?"该进程无法访问该文件,因为它正在被另一个进程使用。"
下面是我的代码。
@echo off
:version_chk
SET USER_VER=1.1.2-RC
ECHO * * * * * * * * * * * * *
ECHO CHECKING FOR UPDATES...
ECHO * * * * * * * * * * * * *
cd "%userprofile%\Downloads"
mkdir "%userprofile%\Downloads\VersionCheckWillDelete"
cd "%userprofile%\Downloads\VersionCheckWillDelete"
powershell -Command "Invoke-WebRequest https://github.com/KSanders7070/AIRPORT_ALIAS_CREATION/blob/master/Version_Check -OutFile 'version_check.HTML'"
findstr "VERSION-" "version_check.HTML" >> "GitHub_Version.txt"
cd "%userprofile%\Downloads\VersionCheckWillDelete"
for /f "delims=" %%x in (GitHub_Version.txt) do set GH_VER_STRING_ORIGINAL=%%x
for /f "tokens=2 delims=<" %%x in ("%GH_VER_STRING_ORIGINAL%") do set GH_VER_STRING_FIRST_HALF=%%x
SET "GH_VER=%GH_VER_STRING_FIRST_HALF:*VERSION-=%"
if %USER_VER% == %GH_VER% GOTO NORMAL_PROCESS
:UPDATE_AVAIL
CLS
START "" "https://github.com/KSanders7070/AIRPORT_ALIAS_CREATION/releases"
ECHO * * * * * * * * * * * * *
ECHO UPDATE AVAILABLE
ECHO * * * * * * * * * * * * *
ECHO.
ECHO.
ECHO GITHUB VERSION: %GH_VER%
ECHO YOUR VERSION: %USER_VER%
ECHO.
ECHO.
ECHO PLEASE CLOSE THIS BATCH FILE AND GO DOWNLOAD THE MOST RECENT UPDATE AVAILABLE:
ECHO.
ECHO https://github.com/KSanders7070/AIRPORT_ALIAS_CREATION/releases
ECHO.
ECHO.
ECHO OR YOU MAY PRESS ANY KEY TO CONTINUE USING THIS VERSION.
ECHO.
ECHO.
cd "%userprofile%\Downloads"
rd /S /Q "%userprofile%\Downloads\VersionCheckWillDelete\"
PAUSE
:NORMAL_PROCESS
CLS
cd "%userprofile%\Downloads"
rd /S /Q "%userprofile%\Downloads\VersionCheckWillDelete\"
ECHO Your BATCH file is the most up to date version.
PAUSE
解决方案:去掉START "URL "行,让BATCH删除该文件夹。不知道为什么要依赖Chrome,但它解决了这个问题。因此,将RD命令放在START""命令之前,使我的一切工作。
为了删除目录,你需要使用这个命令。
rmdir path
del -f path
完全没有理由将目录改为 %UserProfile%\Downloads\VersionCheckWillDelete
,在第一种情况下。此外,可能没有理由使用的是 Downloads
的目的之一的情况下。%Temp%
目录。无论您选择哪一种,您只需要将它用于 version_check.html
文件,所以为什么不直接把它放到所选的位置,而不是创建一个新的目录,然后再删除它。(这样你只需要在必要时删除文件,我希望在每次运行时,文件无论如何都会被覆盖).
这就是说,我可能会这样做你在做什么。
@Echo Off
Set "USER_VER=1.1.2-RC"
Echo * * * * * * * * * * * * *
Echo CHECKING FOR UPDATES...
Echo * * * * * * * * * * * * *
Echo(
If Not Exist "%UserProfile%\Downloads\VersionCheckWillDelete\" MD "%UserProfile%\Downloads\VersionCheckWillDelete"
%__AppDir__%WindowsPowerShell\v1.0\powershell.exe -NoProfile -Command "Invoke-WebRequest -URI \"https://github.com/KSanders7070/AIRPORT_ALIAS_CREATION/blob/master/Version_Check\" -OutFile \"%UserProfile%\Downloads\VersionCheckWillDelete\version_check.html\""
For /F "Tokens=3 Delims=><" %%G In ('%__AppDir__%findstr.exe ">VERSION-[0-9]" "version_check.html"') Do For /F "Tokens=1* Delims=-" %%H In ("%%G") Do Set "GH_VER=%%I"
RD "%UserProfile%\Downloads\VersionCheckWillDelete"
If "%USER_VER%" == "%GH_VER%" Echo Your batch file is the most up to date version.& GoTo Continue
ClS
Echo * * * * * * * * * * * * *
Echo UPDATE AVAILABLE
Echo * * * * * * * * * * * * *
Echo(
Echo GITHUB VERSION: %GH_VER%
Echo YOUR VERSION: %USER_VER%
Echo(
Echo YOU ARE NOT USING THE LATEST VERSION!
Echo(
Echo 1. DOWNLOAD THE LATEST VERSION NOW
Echo 2. CONTINUE USING THIS OUTDATED VERSION
Echo(
%__AppDir__%choice.exe /C 12
If ErrorLevel 2 GoTo Continue
Echo Your Web Browser will now open on the Releases page and this batch file will close.
%__AppDir__%timeout.exe /T 5
Start "" "https://github.com/KSanders7070/AIRPORT_ALIAS_CREATION/releases"
GoTo :EOF
:Continue
Echo(
Echo Continuing . . .
Pause
ClS