Hi,
I want to delete the files in a folder which are more than 90 days older based on the date modified column in the folder in a batch script. Please help.
Thanks
batch script for deleting files 90 days older
Moderator: DosItHelp
-
- Posts: 51
- Joined: 10 Jan 2018 15:21
Re: batch script for deleting files 90 days older
Thank you Very much.
-
- Posts: 51
- Joined: 10 Jan 2018 15:21
Re: batch script for deleting files 90 days older
Hi,
I tried this with the local path, it worked perfectly fine. But when given a share drive path, it shows me an error as
Error: UNC paths (\\machine\share) are not supported.
here is What I am trying.
SET "NASS=\\abc"
SET "TEMPDIR=!NASS!\CU\OR"
forfiles /p "%TEMPDIR%\OR" /s /m *.* /c "cmd /c Del @path" /d -90
Can anyone please see?
I tried this with the local path, it worked perfectly fine. But when given a share drive path, it shows me an error as
Error: UNC paths (\\machine\share) are not supported.
here is What I am trying.
SET "NASS=\\abc"
SET "TEMPDIR=!NASS!\CU\OR"
forfiles /p "%TEMPDIR%\OR" /s /m *.* /c "cmd /c Del @path" /d -90
Can anyone please see?
Re: batch script for deleting files 90 days older
Nobody can magically make FORFILES work with UNC paths. FORFILES is LITERALLY telling you that it does not work with UNC paths. Not sure why you are using delayed expansion either.lalat06bag wrote: ↑08 Nov 2018 16:43Hi,
I tried this with the local path, it worked perfectly fine. But when given a share drive path, it shows me an error as
Error: UNC paths (\\machine\share) are not supported.
here is What I am trying.
SET "NASS=\\abc"
SET "TEMPDIR=!NASS!\CU\OR"
forfiles /p "%TEMPDIR%\OR" /s /m *.* /c "cmd /c Del @path" /d -90
Can anyone please see?
Use PUSHD and POPD to work around the limitation.
Code: Select all
SET "NASS=\\abc"
SET "TEMPDIR=%NASS%\CU\OR"
PUSHD "%TEMPDIR%"
forfiles /s /m *.* /c "cmd /c Del @path" /d -90
POPD
-
- Posts: 51
- Joined: 10 Jan 2018 15:21
Re: batch script for deleting files 90 days older
Thank you a ton! This worked perfectly fine!
-
- Posts: 51
- Joined: 10 Jan 2018 15:21
Re: batch script for deleting files 90 days older
Hi,
While running this script, we figured out that we need to keep few files irrespective of their dates. I have below files which we need to keep. They are all ending with -en-us.
sorry for bugging. kindly see. All files older than 90 days will be removed except the below ones ending with -en-us.
ex:
XXXyy-en-us
ssxx-en-us
wtdt09-en-us
Thanks
While running this script, we figured out that we need to keep few files irrespective of their dates. I have below files which we need to keep. They are all ending with -en-us.
sorry for bugging. kindly see. All files older than 90 days will be removed except the below ones ending with -en-us.
ex:
XXXyy-en-us
ssxx-en-us
wtdt09-en-us
Thanks
Re: batch script for deleting files 90 days older
You could use forfiles to echo the files you want to move (inclucing surrounding doublequotes) instead of deleting them and redirect the result to a temporary file. Then use findstr to filter the ones you want to keep.
penpen.
penpen.