Windows 7 Forums Search
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows 7. The Windows 7 forum also covers news and updates and has an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7 - Batch file

 
03-22-2011   #1


Windows 7 Home Premium x64 SP 1
 
 

Batch file

I've created a batch file I use to remove some backup files (.bak) that seem stubborn to leave. However, and this is on an XP laptop, not Windows 7, I've discovered that there is a critical data.bak file that must remain (again, XP, not Windows 7) so that MS Office XP will work. When the file is deleted, Office programs will not start without reinstalling "the component."

So is there a switch or separate command I can use with the line "del c:\*.bak /s" that would delete all *.bak files except this one: c:\documents and settings\all users\application data\microsoft\office\data\data.bak?

Thanks.

My System SpecsSystem Spec
03-23-2011   #2


Windows 7 Ultimate x64 Service Pack 1
 
 


The del command doesn't have a switch in particular to achieve what you wish and since they are all ending with the bak extension, wildcards won't be of much help.

I don't know if it's helpful but maybe if you can set the file to have a certain attirbute, you can exclude it. There is a switch to the del command that will exclude the file based on it's attribute. Here's the complete listing of switches thanks to the del /? command.

Code:
DEL [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names
ERASE [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names

  names         Specifies a list of one or more files or directories.
                Wildcards may be used to delete multiple files. If a
                directory is specified, all files within the directory
                will be deleted.

  /P            Prompts for confirmation before deleting each file.
  /F            Force deleting of read-only files.
  /S            Delete specified files from all subdirectories.
  /Q            Quiet mode, do not ask if ok to delete on global wildcard
  /A            Selects files to delete based on attributes
  attributes    R  Read-only files            S  System files
                H  Hidden files               A  Files ready for archiving
                -  Prefix meaning not

If Command Extensions are enabled DEL and ERASE change as follows:

The display semantics of the /S switch are reversed in that it shows
you only the files that are deleted, not the ones it could not find.
My System SpecsSystem Spec
03-23-2011   #3


 
 


Hi,

You could add a couple of extra lines to your batch file that will rename the file, perform the delete then rename again

Code:
c:
cd "documents and settings\all users\application data\microsoft\office\data"
ren data.bak data.new
cd\
[insert delete code here]
c:
cd "documents and settings\all users\application data\microsoft\office\data"
ren data.new data.bak
cd\
It should then rename the file both before and after the delete script, keeping it intact.


OS
My System SpecsSystem Spec
.


03-23-2011   #4


Windows 7 Ultimate x64 Service Pack 1
 
 


Quote   Quote: Originally Posted by Orbital Shark View Post
Hi,

You could add a couple of extra lines to your batch file that will rename the file, perform the delete then rename again

Code:
c:
cd "documents and settings\all users\application data\microsoft\office\data"
ren data.bak data.new
cd\
[insert delete code here]
c:
cd "documents and settings\all users\application data\microsoft\office\data"
ren data.new data.bak
cd\
It should then rename the file both before and after the delete script, keeping it intact.


OS
That's an even better suggestion! I didn't think of that.
My System SpecsSystem Spec
03-23-2011   #5


Windows 7 Home Premium x64 SP 1
 
 


OK, OS. Great idea. I'll try that. Thanks.
And thanks oreo27. That might also work.
My System SpecsSystem Spec
03-23-2011   #6


Windows 7 Ultimate x64 Service Pack 1
 
 


Quote   Quote: Originally Posted by gogreen View Post
OK, OS. Great idea. I'll try that. Thanks.
And thanks oreo27. That might also work.
No problem mate! Cheers!
My System SpecsSystem Spec
03-27-2011   #7


Windows 7 Home Premium x64 SP 1
 
 


I solved this problem by simply removing the "del c:\*.bak /s" line. That computer rarely has *.bak files, anyway. I'm just glad I discovered why I kept getting a message to install a feature when I tried to go into MS Office products!
My System SpecsSystem Spec
03-27-2011   #8


Windows 7 Ultimate x64 Service Pack 1
 
 


Quote   Quote: Originally Posted by gogreen View Post
I solved this problem by simply removing the "del c:\*.bak /s" line. That computer rarely has *.bak files, anyway. I'm just glad I discovered why I kept getting a message to install a feature when I tried to go into MS Office products!
Well, at least you're satisfied now. Congratulations mate!
My System SpecsSystem Spec
03-27-2011   #9


Windows 7 Home Premium x64 SP 1
 
 


Quote   Quote: Originally Posted by oreo27 View Post
Quote   Quote: Originally Posted by gogreen View Post
I solved this problem by simply removing the "del c:\*.bak /s" line. That computer rarely has *.bak files, anyway. I'm just glad I discovered why I kept getting a message to install a feature when I tried to go into MS Office products!
Well, at least you're satisfied now. Congratulations mate!
Yeah, thanks. Sometimes it takes a little thinking to come up with the obvious solution!
My System SpecsSystem Spec
Reply

 Batch file problems?



Thread Tools



Similar Threads for: Batch file
Thread Forum
Help required creating batch file to read .csv file General Discussion
batch file open file for program in the startup folder General Discussion
How to create a batch file that will move files based on the file type General Discussion
Batch file for... Customization
Need Help with Batch File General Discussion


All times are GMT -5. The time now is 01:07 AM.



Windows 7 Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows 7" and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30