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
Batch file to delete files over 10 days old
Moderator: DosItHelp
Re: Batch file to delete files over 10 days old
AFAIK you have to substitude @FILE by \"@FILE\" .
Regards
aGerman
Regards
aGerman
Re: Batch file to delete files over 10 days old
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
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
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:
Regards
aGerman
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
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
"-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