Why can't I delete the contents of the 'INetCache' folder from the command prompt? - windows

I'm using Windows 10 and need to update a batch file to clear the contents of folder at "C:\Users\myUserName\AppData\Local\Microsoft\Windows\INetCache". This is the folder that holds cache for Internet Explorer.
I would have thought the command was simply as follows:
DEL /S /F /Q C:\Users\myUserName\AppData\Local\Microsoft\Windows\INetCache\*
This command executes without issue, but when I look at the contents of the folder via Windows Explorer, it still has stuff in it. I say "stuff" because while it looks like a bunch of files, they don't behave like typical files. For instance, I cannot see these files when when I use "dir" on the command prompt no matter which flags I utilize. And when I examine the properties of these files, there is barely any information associated with them.
Why isn't my DEL command clearing out these files?
Screenshot of "files" still present in my INetCache folder
Screenshot of the properties of one of these files

I found that using the "rmdir" command instead of the "del" command resolved my issue.
rmdir "C:\Users\myUserName\AppData\Local\Microsoft\Windows\INetCache" /s /q

open txt and save .bat file
DEL /S /F /Q C:\Users\%username%\AppData\Local\Microsoft\Windows\INetCache\*
pause

Related

How to delete a directory from within that same directory with a batch file?

call :deleteSelf&exit /b
:deleteSelf
start "" /D "C:\Windows" /MIN cmd /c RD /S /Q "C:\Windows\test"&&exit /b
This is the code I use. Batch file running it sits within C:\Windows\test
The file is successfully deleted, along with any other files in the directory, but not the directory itself. Does anyone know some way to solve this issue? I'm rather stumped.
You will need, at least, to
leave the current batch file so it is not open
ensure your current active directory is not the one you want to remove
so, if you follow the already pointed dbenham's approach for leaving the current batch file you could use something like
((goto) 2>nul & cd "%~dp0\.." && rmdir /s /q "%~dp0")
That is,
the (goto) will generate an error that will leave current batch file execution
we change the current active directory to the parent of the folder where the batch file is stored
it the active directory has been changed, we try to remove the folder that holds the batch file
Of course, if there is another process/file locking the folder you will not be able to remove it.
surely it's not as easy as adding the following line to your batch file:
cd c:\
rd c:\windows\test

How do I make a batch file delete it's own directory?

Okay, I apologize that I am very new at this, but I am trying to make my batch file delete it's own directory after it has been launched. This is how my folders are arranged:
Folder1
delete.bat
My goal is to make "delete.bat" delete "Folder1" after "delete.bat" has been launched. So here's my code:
rd /s /q %~dp0..\Folder1
This seems like it would work but it only deletes the contents of "Folder1" rather than the whole directory itself. What am I doing wrong?
Some thoughts...
%~dp0 gets the drive and path of the batch file, so you don't need to include ..\Folder1.
What you have should work. If it's not removing the folder itself, it means that it's locked, probably because cmd's current folder is Folder1. (That's a likely guess, but it's not the only reason it might be locked.) If it is cmd, you'll have to call the batch file from another folder, outside of Folder1.
While what you have will work, it will result in a funny error when resuming the non-existent batch file: The system cannot find the path specified. You can avoid that in the solution below.
One good solution: start /b "" cmd /c rd /s /q "%~dp0"
This creates a new process to remove the folder (and everything in it, including the batch file itself). Be careful. =)
From the corresponding MSDN link for rd:
You cannot use rmdir to delete the current directory. You must first change to a different directory (not a subdirectory of the current directory) and then use rmdir with a path.
I guess this is what's going wrong in your case since the batch file is located within the directory that you're trying to delete.
My implementation is effectively the same as Soja's, plus the info from dbenham's comment. I have added a 2-sec delay, to ensure there are no timing issues, even though I believe the error when the .bat file is deleting itself is harmless.
#echo off
:: Do the work
...your command here...
:: In order to delete the current dir we are running from (and all subdirs), none of them can be the
:: current working directory of any running process. Therefore, we are setting our own CWD to something
:: else, so it will be inherited by the below cmd.exe.
cd /d %temp%
:: The countdown is there to allow this batch file to exit, so it can then be deleted safely.
set DelayedSelfDeleteCommand="timeout /t 2 >NUL && rmdir /s /q "%~dp0""
:: Start a separate process (without waiting for it), to execute the command
start "" /b cmd.exe /C %DelayedSelfDeleteCommand%
Well I think it cannot be done (at least as normal user)
start /b "" cmd /c rd /s "%~dp0"
deletes folder but only with right permissions I think
start /b "" cmd /c rmdir /s "C:/folder"
This has the same result
del /s /q "C:\Temp\folder\*"
rmdir /s /q "C:\Temp\folder"
del %0
only way as for batch files is to use vbs script or autohotkey (send !{Space} // send e // send p formula) or hack it, you can delete only file used and content of folder but not working directory due to specification of cmd. Any other language would have no problem with it cuz it in RAM memory.
I recommend this way to do it (as for normal users):
in your bat file add
copy C:\urpath\deleteafter.bat C:\Temp\deleteafter.bat
start "" autohotkey.exe "X:\patchto\deletebatchfile.ahk"
deletebatchfile.ahk
sleep 2000
Run, C:\Temp\deleteafter.bat, C:\Temp\
deleteafter.bat
rmdir /s /q "C:\Temp\batfileworkingpath"
sleep 3
del %0

Deleting log files windows

I need to make a batch file that can search the hard-drive for log files and remove them. Does any one know a code that I can use. I am using windows 7.
If you are certain that all *.log files on a drive can be deleted with no after effects, then this will delete the log files that are not in use:
#echo off
del \*.log /s /f /q

Accelerating file deletion on windows

I wish to delete a lot of files on windows quickly as possible.
Got any suggestions on how to do it (in batch script, windows command or ant script etc.)?
I was thinking of the following directions:
Parallel deletion. It apperats that when I delete a bunch of files it takes longer than deleting groups of these files parallely.
Any (quick!) way to make these files on creation time to "sit" closely on the disk?
Any optimizations in deletion, given that the deletion is permanat?
Any lazy mechanism windows has. That is, it doesn't really delete the files at that moment, but creates the effect that it did (you won't see it on the cmd.exe dir command or on the gui, and you could create a new file with a name that used to exist etc.) and windows will continue the real deletion in the background.
Any input will be extremely helpfull,
Thank you.
I find that the command line tends to be faster with file operations. For example, to delete C:\Parent\Folder\OldFolder, open the Command Prompt and type:
CD "C:\Parent\Folder"
Attrib -R -S -H "OldFolder\*.*" /S /D /L
RD /S /Q "OldFolder"
You could try using the commmand line as Hand-E-Food said. You can use these commands to delete files and remove folders.
del /f /s /q
rd /s /q
Or use wildcards to wipe all files out from a directory:
del C:\filestodel\*.* /f /s /q

What's the fastest way to delete a large folder in Windows?

This question's answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions.
I want to delete a folder that contains thousands of files and folders. If I use Windows Explorer to delete the folder it can take 10-15 minutes (not always, but often). Is there a faster way in Windows to delete folders?
Other details:
I don't care about the recycle bin.
It's an NTFS drive.
The worst way is to send to Recycle Bin: you still need to delete them. Next worst is shift+delete with Windows Explorer: it wastes loads of time checking the contents before starting deleting anything.
Next best is to use rmdir /s/q foldername from the command line. del /f/s/q foldername is good too, but it leaves behind the directory structure.
The best I've found is a two line batch file with a first pass to delete files and outputs to nul to avoid the overhead of writing to screen for every singe file. A second pass then cleans up the remaining directory structure:
del /f/s/q foldername > nul
rmdir /s/q foldername
This is nearly three times faster than a single rmdir, based on time tests with a Windows XP encrypted disk, deleting ~30GB/1,000,000 files/15,000 folders: rmdir takes ~2.5 hours, del+rmdir takes ~53 minutes. More info at Super User.
This is a regular task for me, so I usually move the stuff I need to delete to C:\stufftodelete and have those del+rmdir commands in a deletestuff.bat batch file. This is scheduled to run at night, but sometimes I need to run it during the day so the quicker the better.
Technet documentation for del command can be found here. Additional info on the parameters used above:
/f - Force (i.e. delete files even if they're read only)
/s - Recursive / Include Subfolders (this definition from SS64, as technet simply states "specified files", which isn't helpful).
/q - Quiet (i.e. do not prompt user for confirmation)
Documentation for rmdir here. Parameters are:
/s - Recursive (i.e. same as del's /s parameter)
/q - Quiet (i.e. same as del's /q parameter)
Using Windows Command Prompt:
rmdir /s /q folder
Using Powershell:
powershell -Command "Remove-Item -LiteralPath 'folder' -Force -Recurse"
Note that in more cases del and rmdir wil leave you with leftover files, where Powershell manages to delete the files.
use fastcopy, a free tool.
it has a delete option that is a lot faster then the way windows deletes files.
use the command prompt, as suggested. I figured out why explorer is so slow a while ago, it gives you an estimate of how long it will take to delete the files/folders. To do this, it has to scan the number of items and the size. This takes ages, hence the ridiculous wait with large folders.
Also, explorer will stop if there is a particular problem with a file,
and to delete a lot of folders, you could also create a batch file with the command spdenne posted.
1) make a text file that has the following contents replacing the folder names in quotes with your folder names:
rmdir /s /q "My Apps"
rmdir /s /q "My Documents"
rmdir /s /q "My Pictures"
rmdir /s /q "My Work Files"
2) save the batch file with a .bat extension (for example deletefiles.bat)
3) open a command prompt (Start > Run > Cmd) and execute the batch file. you can do this like so from the command prompt (substituting X for your drive letter):
X:
deletefiles.bat
Try Shift + Delete. Did 24.000 files in 2 minutes for me.

Resources