简体   繁体   English

批处理文件以删除另一个文件夹内的文件夹

[英]a batch file to delete a folder which is inside another folder

On windows 7, How can i write a batch file to delete a folder which is inside another folder. 在Windows 7上,如何编写批处理文件以删除另一个文件夹中的文件夹。 this 'another folder' name varies. 这个“另一个文件夹”的名称有所不同。

Eg: C:\Users\%USERNAME%\AppData\Local\Mozilla\Firefox\Profiles\xxxxxx\cache2 

the 'xxxxxx' might change. “ xxxxxx”可能会更改。 Now, i want to delete the 'cache2' folder and all its contents. 现在,我想删除“ cache2”文件夹及其所有内容。

i tried this: 我尝试了这个:

:: Batch script to clear browsing history, download history, and empty the cache for     Mozila Firefox.
:: Script can be run via GFI MAX RM 
@echo off
TASKKILL /T /F /IM Firefox.exe
set DataDir=C:\Users\%USERNAME%\AppData\Local\Mozilla\Firefox\Profiles
del /q /s /f "%DataDir%"
rd /s /q "%DataDir%"
for /d %%x in (C:\Users\%USERNAME%\AppData\Roaming\Mozilla\Firefox\Profiles\*) do del     /q /s /f %%x\*sqlite
start "" "C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
cls
IF %ERRORLEVEL%==0 (
@echo "Success Message"
timeout 10
) ELSE (
@echo "Error Message"
timeout 10
exit 1001
)

but this is deleting the entire profiles folder. 但这将删除整个配置文件文件夹。

can anyone out there please help me out with this. 外面有人可以帮我吗

for /d %%a in (
    "C:\Users\%USERNAME%\AppData\Local\Mozilla\Firefox\Profiles\*"
) do if exist "%%~fa\cache2\" echo rmdir /s /q "%%~fa\cache2"

For each folder under the Profiles folder, if it contains a cache2 subfolder, remove it. 对于“ Profiles文件夹下的每个文件夹,如果它包含cache2子文件夹,请将其删除。

rmdir commands are only echoed to console. rmdir命令仅回显到控制台。 If the output is correct, remove the echo command 如果输出正确,请删除echo命令

简单:

rmdir /s C:\Users\%USERNAME%\AppData\Local\Mozilla\Firefox\Profiles\xxxxxx\cache2

If you know that your cache2 folder is a direct child of xxxxxx, then MC ND has a good answer. 如果您知道您的cache2文件夹是xxxxxx的直接子级,则MC ND有一个不错的答案。 But if cache2 can appear at any level, then the following works, providing that cache2 is not a direct decendent of "...\\Profiles\\". 但是,如果cache2可以出现在任何级别,则只要cache2不能直接取代“ ... \\ Profiles \\”,就可以进行以下操作。

@echo off
for /f "delims=" %%F in ('dir /b /ad /s "C:\Users\%USERNAME%\AppData\Local\Mozilla\Firefox\Profiles\cache2"') do echo rd /s /q "%%F"

If cache2 can be a direct child of "...\\Profiles", then the following should work as long as there are no folders with a name like "cache2.x". 如果cache2可以是“ ... \\ Profiles”的直接子代,则只要没有名称类似于“ cache2.x”的文件夹,以下内容就可以工作。

@echo off
for /f "delims=" %%F in ('dir /b /ad /s "C:\Users\%USERNAME%\AppData\Local\Mozilla\Firefox\Profiles\cache2.?"') do echo rd /s /q "%%F"

Both commands above simply ECHO the RD statements. 上面的两个命令都只是ECHO RD语句。 Simply remove ECHO when all looks correct. 当一切看起来正确时,只需删除ECHO。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM