Jump to content

Batch file to delete specific folders


Recommended Posts

Greetings

I m trying to create a batch file in a way that - if i run it - it will delete the content inside specific folders: Those folders are the below:

 

C:\Windows\Prefetch

C:\Windows\Temp

C:\Users\Haris\AppData\Local\Temp

 

Can anyone help?

 

Thanks

Edited by Haris1977
Link to comment
Share on other sites


1 hour ago, Haris1977 said:

Greetings

I m trying to create a batch file in a way that - if i run it - it will delete the content inside specific folders: Those folders are the below:

And what have you tried (that presumably did not work as you expected)?

Or is the request slightly different, more *like* "please write for me a batch that does this ..." :dubbio:

Anyway, see if any of the solutions here fits your usage:

https://stackoverflow.com/questions/6836566/batch-file-delete-all-files-and-folders-in-a-directory

Easiest is to use RD and the re-create the "base folder", but it is to be seen if that is OK in your situation (basically the recreated "base" directory will have a different creation date",

Additionally if the volume - as it is likely the case - is NTFS, there might be the need to check for hardinks before deleting files unconditionally :ph34r:.

jaclaz
 

 

Edited by jaclaz
Link to comment
Share on other sites

Thanks for your answer

I ve managed to create this script:

del /s /f /q "C:\Windows\Prefetch\*.*"
del /s /f /q "C:\Windows\Temp\*.*"
del /s /f /q "C:\Users\Haris\AppData\Local\Temp\*.*"
echo Deleting Files!
timeout /t 3

While it works, inside "prefetch" folder there are still 4files that are recreated when the batch file ends:

 

CMD.EXE-8E75B5BB.pf

CONHOST.EXE-E6AFC9F5.pf

TIMEOUT.EXE-579F197A.pf

DLLHOST.EXE-57A853C4.pf

 

Any idea why those files are re created?

Edited by Haris1977
Link to comment
Share on other sites

12 hours ago, Haris1977 said:

While it works, inside "prefetch" folder there are still 4files that are recreated when the batch file ends:

 

CMD.EXE-8E75B5BB.pf

CONHOST.EXE-E6AFC9F5.pf

TIMEOUT.EXE-579F197A.pf

DLLHOST.EXE-57A853C4.pf

 

Any idea why those files are re created?

Sure :yes:, I would say it is "normal".

The prefetch folder is where Windows automagically creates *something* (let's call for the moment  this *something* "links") connected to frequently used executables.

Cmd.exe and Timeout.exe are the command processor (that runs the batch) and the  command you used in the batch, conhost.exe is as well connected to the command processor (it is the console host) and dllhost.exe (likely, haven't checked) is connected to timeout.exe (or as well to cmd.exe).

If you don't want them to be recreated you need to disable prefetch:
https://www.technipages.com/windows-enable-disable-superfetch

It may also depend on its actual setting, check the values in:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SessionManager\Memory Management\PrefetchParameters

EnablePrefetcher

EnableSuperfetch

https://www.tomshardware.com/reviews/ssd-performance-tweak,2911-5.html

jaclaz

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...