Page 1 of 1

Deleting only certain files from specified location and its sub-folders [SOLVED]

Posted: 28 Apr 2023 12:25
by DOSadnie
I want to automatically get rid of e.g. temporary files of Excel which sometimes are left over after its crash. Such file can look like this
~$OriginalNameOfMyFile.xlsm
Lets say they are in a folder like

S:\Data

and its sub-folders and their sub-folders


I tried using

Code: Select all

forfiles /s /m "~$*.xlsm" /c "cmd /c del @path" /p "S:\Data"
and

Code: Select all

for /r "S:\Data" %x in (~$*.xlsm) do del "%x"
and some variants of them but I was not able to write a working one


Was it because such temporary files have the hidden attribute applied to them?

Re: Deleting only certain files from specified location and its sub-folders

Posted: 29 Apr 2023 06:08
by bxx
Use del /A to delete hidden files, like

Code: Select all

del /A *.xlsm

Re: Deleting only certain files from specified location and its sub-folders

Posted: 25 Jun 2023 08:34
by DOSadnie
This seems to work

Code: Select all

cd /D S:\Data
del /AH *.xlsm
So thank you for your help


The only caveat is that there is no fail-safe in form of files going to the Recycle Bin, as they are just deleted permanently

Re: Deleting only certain files from specified location and its sub-folders

Posted: 25 Jun 2023 09:05
by miskox
Maybe you add /s to delete if required.

Saso

Re: Deleting only certain files from specified location and its sub-folders

Posted: 01 Jul 2023 04:19
by DOSadnie
Add for gaining that fail-safe of sending files to the Recycle Bin?

If yes- then it does not work

Re: Deleting only certain files from specified location and its sub-folders

Posted: 15 Jul 2023 05:06
by DOSadnie
As the initial question had been answered, I have just created a separate topic for the newer one: viewtopic.php?f=3&t=10858