Page 1 of 1
Batch file to delete files over 10 days old
Posted: 20 May 2010 03:35
by h17rj0
Hi,
Can someone please help me I have created a batch file that deletes files over 10days old. I have managed to do this but this will not delete files with spaces in the name, any ideas?
forfiles "-pC:\Documents and Settings\admin\Desktop\New Folder" -m*.* -d-10 -s -c"cmd /c del /k @FILE| echo @FILE"
apologies in advance, if anything is wrong, i'm a newbie.
thanks
Harj
Re: Batch file to delete files over 10 days old
Posted: 20 May 2010 11:42
by aGerman
AFAIK you have to substitude @FILE by \"@FILE\" .
Regards
aGerman
Re: Batch file to delete files over 10 days old
Posted: 21 May 2010 07:36
by h17rj0
hey excellent thanks agerman.
can you tell me how i need to amend the path so this works on the server.
so instead of "-pC:\Documents and Settings\admin\Desktop\New Folder" -m*.* -d-10 -s -c"cmd /c del /k @FILE| echo @FILE"
i thought i could do
"-p\\server address" -m*.* -d-10 -s -c"cmd /c del /k @FILE| echo @FILE". but this does not work any ideas?
thanks again
Re: Batch file to delete files over 10 days old
Posted: 21 May 2010 11:14
by aGerman
Hmm. I never used FORFILES (because it's not available on each computer). But I didn't found any documentation to use it with a server path too.
So, my recommendation would be connecting the server share with a drive letter.
Example:
Code: Select all
net use X: "\\server address\share"
forfiles -p X:\ .......your stuff
net use X: /delete
Regards
aGerman
Re: Batch file to delete files over 10 days old
Posted: 26 May 2010 04:54
by alan_b
I know nothing of FORFILES etc. but my attention is focussed on this snippet
"-pC:\Documents and Settings\admin\Desktop\New Folder"
To avoid problems with embedded spaces the file path/name need encapsulating with quotes.
Just possibly this might work if the -p argument is confusing the quotes whilst within them
-p"C:\Documents and Settings\admin\Desktop\New Folder"
A very plausible solution is to use the short names and avoid embedded spaces,
i.e.
C:\Documents and Settings\admin\Desktop\New Folder
becomes
C:\DOCUME~1\admin\Desktop\NEWFOL~1
I determine the short name by appending /X to the DIR command,
which then displays both the short and the long names for the files and folders.
There may be alternative solutions.
WARNING - danger if C:\DOCUME~2\ also exists :-
C:\DOCUME~1\ does NOT necessarily refer to C:\Documents and Settings\
If you have an additional folder with the name C:\Documents to Purge\
then amongst the short names you will have C:\DOCUME~1\ and C:\DOCUME~2\,
and I would not like to predict which short name refers to which long name.
Alan