This script clears the Firefox cache for the first profile in the directory. How do you do the same thing to every profile found if there are more than one? As you can see, I don't want to delete the folders named cache2, doomed, and entries. I just want to wipe their content.
CD /D %LOCALAPPDATA%\Mozilla\Firefox\Profiles\**.default\cache2
FOR /F "DELIMS=" %%I IN ('DIR /B') DO IF NOT "%%I"=="doomed" IF NOT "%%I"=="entries" (RMDIR "%%I" /S /Q || DEL "%%I" /S /Q)
CD /D %LOCALAPPDATA%\Mozilla\Firefox\Profiles\**.default\cache2\doomed
FOR /F "DELIMS=" %%I IN ('DIR /B') DO (RMDIR "%%I" /S /Q || DEL "%%I" /S /Q)
CD /D %LOCALAPPDATA%\Mozilla\Firefox\Profiles\**.default\cache2\entries
FOR /F "DELIMS=" %%I IN ('DIR /B') DO (RMDIR "%%I" /S /Q || DEL "%%I" /S /Q)
Related
I found this on S.O.:
for /f "eol=: delims=" %%F in ('dir /b /ad^|findstr /vxilg:"keep.txt"') do rd /q /s "%%F"
Where do I specify the folder path of the folders I want to delete?
Use pushd to temporarily change to the folder to process and popd to restore the original one:
pushd "D:\your\folder\path" && ((for /f "eol=: delims=" %%F in ('dir /b /ad^|findstr /vxilg:"keep.txt"') do rd /q /s "%%F") & popd)
The && operator avoids the following command(s) to be executed when your folder path cannot be found.
set "folder=C:\My Folder"
for /f "eol=: delims=" %%F in ('dir /b /ad "%folder%" ^|findstr /vxilg:"keep.txt"') do rd /q /s "%folder%\%%F"
I have created a batch file which should keep the 4 newest folders on a network. This is because it is a back up of one of the computers.
I tested it first on my own system and it worked correctly. After testing I copied the batch to the other system and let it run by the Task Scheduler of Windows. It does make back ups, but it will not remove the oldest folders. I gave that task all needed permissions. I will paste the code here, because I think there could be a fault in the code.
#echo off
WMIC.EXE Alias /? >NUL 2>&1 || GOTO s_error
FOR /F "skip=1 tokens=1-6" %%G IN ('WMIC Path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:table') DO (
IF "%%~L"=="" goto s_done
Set _yyyy=%%L
Set _mm=00%%J
Set _dd=00%%G
)
:s_done
Set _mm=%_mm:~-2%
Set _dd=%_dd:~-2%
Set _isodate=%_yyyy%-%_mm%-%_dd%
Echo %_isodate%
#echo off
for /F "skip=4 delims=" %%I in ('dir "\\server\Folder1\folder2\backup1\backup1_*" /AD /B /O-N 2^>nul') do rd /Q /S "\\server\Folder1\folder2\backup1\%%I"
for /F "skip=4 delims=" %%I in ('dir "\\server\Folder1\folder2\backup2\backup2_*" /AD /B /O-N 2^>nul') do rd /Q /S "\\server\Folder1\folder2\backup2\%%I"
for /F "skip=4 delims=" %%I in ('dir "\\server\Folder1\folder2\backup3\backup3_*" /AD /B /O-N 2^>nul') do rd /Q /S "\\server\Folder1\folder2\backup3\%%I"
for /F "skip=4 delims=" %%I in ('dir "\\server\Folder1\folder2\backup4\backup4_*" /AD /B /O-N 2^>nul') do rd /Q /S "\\server\Folder1\folder2\backup4\%%I"
#echo off
cd C:\
ROBOCOPY "C:\backup1" "\\server\Folder1\folder1\backup1\backup1"_%_isodate% /COPYALL /E /W:5 /R:5
ROBOCOPY "C:\backup2" "\\server\Folder1\folder2\backup2\backup2"_%_isodate% /COPYALL /E /W:5 /R:5
ROBOCOPY "C:\backup3" "\\server\Folder1\folder2\backup3\backup3"_%_isodate% /COPYALL /E /W:5 /R:5
ROBOCOPY "C:\backup4" "\\server\Folder1\folder2\backup4\backup4"_%_isodate% /COPYALL /E /W:5 /R:5
The name 'Folder' is used to indicate a regular folder, the name 'Backup' is used to indicate the backup folder.
I'm looking for script which will remove all folders containing del word in the end of the name but exclude containing prep word.
for /f "delims=" %%i in ('dir /a:d /s /b ?*del') do rd /s /q %%i
This should do the trick :
#echo off
for /f "delims=" %%i in ('dir /a:d /s /b ?*del') do echo %%i | find /i "prep" >nul || rd /s /q "%%i"
I was running batch file script to delete the files in particular folder.the problem is how can i log the files deleted and the date time it is getting deleted in a log file with log file nameappended with date.
set folder="C:\test"
cd /d %folder%
for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)
#echo off
setlocal
set "YMD="
FOR /F "skip=1 tokens=1,2,3" %%A IN ('WMIC Path Win32_LocalTime Get Year^,Month^,Day /Format:table') DO (
if not defined Y set "YMD=%%B%%A%%C"
)
set folder="C:\test"
break>%YMD%.log
for /F "delims=" %%i in ('dir /b %folder%') do (
echo "%%~fi" deleted at %YMD% >>%YMD%.log
rmdir "%%i" /s/q || del "%%i" /s/q
)
?
I'm looking for a batch file that will go into C:\Documents and Settings\ and delete all folders except a few that I want to keep.
Here's a hack-around =D
If you have a list of folder paths in say folders.txt listed as so:
C:\Documents and Settings\Mechaflash
C:\Documents and Settings\Mom
C:\Documents and Settings\Dad
etc. What you can do is temporarily change them to hidden folders, then RMDIR on all non-hidden folders.
CD "C:\Documents and Settings\"
FOR /F "tokens=*" %%A IN (folders.txt) DO (
ATTRIB +H "%%A" /S /D
)
FOR /F "USEBACKQ tokens=*" %%F IN (`DIR /B /A:-HD "C:\Documents and Settings\"`) DO (
RMDIR /S /Q %%A
)
FOR /F "tokens=*" %%A IN (folders.txt) DO (
ATTRIB -H "%%A" /S /D
)
A solution using robocopy:
cd /d "C:\Documents and Settings"
md tmp
robocopy . tmp /E /MOVE /XD folderToKeep1 folderToKeep2 ...
rd /s /q tmp
rem the last space character is deliberate
set yourKeepList="abc def "
for /f %%f in ('dir /b/ad "C:\Documents and Settings"') do (
(echo %yourKeepList% | findstr /v /i "%%f " 1>nul) && rd /q/s %%f
)