Delete all files except

November 5, 2009 at 11:36:04
Specs: Windows XP
Hi

Can anyone help me with an if statment in a batch file. Basically I have a number of Excel files in the Excel Start Folder. One file named PERSONAL.XLS I need to keep. All the other .xls files I need to delete.

If I use:

DEL "C:\Documents and Settings\%username%\Application Data\Microsoft\Excel\XLSTART\*.xls"

then all the files including PERSONAL.XLS are deleted. Any help with some code to delete the files and keep PERSONAL.XLS would be great.


See More: Delete all files except

Report •


#1
November 5, 2009 at 11:44:29
Quick and dirty way...

@Echo off
Copy "C:\Documents and Settings\%username%\Application Data\Microsoft\Excel\XLSTART\PERSONAL.XLS" "C:\Documents and Settings\%username%\Application Data\Microsoft\" 
DEL "C:\Documents and Settings\%username%\Application Data\Microsoft\Excel\XLSTART\*.xls"
Copy "C:\Documents and Settings\%username%\Application Data\Microsoft\PERSONAL.XLS" "C:\Documents and Settings\%username%\Application Data\Microsoft\Excel\XLSTART\"
DEL "C:\Documents and Settings\%username%\Application Data\Microsoft\Excel\PERSONAL.XLS"


Ooops yes, here you go..


Report •

#2
November 5, 2009 at 11:46:37
I have got a good idea:

FileCopy "C:\Documents and Settings\%username%\Application Data\Microsoft\Excel\XLSTART\personal.xls","C:\personal.xls"
DEL "C:\Documents and Settings\%username%\Application Data\Microsoft\Excel\XLSTART\*.xls"

FileCopy "C:\presonal.xls","C:\Documents and Settings\%username%\Application Data\Microsoft\Excel\XLSTART\personal.xls"

DEL "C:\Personal.xls"

..me and the previous poster have similar opinions, but he forgot to clean up...


Report •

#3
November 5, 2009 at 12:43:58
Hi Guys, thanks for the quick responses. Problem solved.

Many thanks. Jack.


Report •

Related Solutions


Ask Question