Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Batch file

22 Mar 2011   #1
gogreen

Windows 10 Home, 64 bit
 
 
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
.
23 Mar 2011   #2
oreo27

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
23 Mar 2011   #3
Orbital Shark

 
 

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
.

23 Mar 2011   #4
oreo27

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
23 Mar 2011   #5
gogreen

Windows 10 Home, 64 bit
 
 

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

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
27 Mar 2011   #7
gogreen

Windows 10 Home, 64 bit
 
 

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
27 Mar 2011   #8
oreo27

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
27 Mar 2011   #9
gogreen

Windows 10 Home, 64 bit
 
 

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




Thread Tools




Similar help and support threads
Thread Forum
How can I write a batch file that opens a file in a program?
I wrote this batch file which does what I want it to do so far. @echo off "C:\Users\xxxxxx\Documents\HideTaskbar\HideTaskbar.exe" "C:\Program Files (x86)\VideoLANold\VLC\vlc.exe" "C:\Users\xxxxxx\Documents\HideTaskbar\ShowTaskbar.exe" exit
General Discussion
I need a batch file to open a random file within a certain folder/path
I want a batch to select and open a random link file in a folder i have. All the links are music videos I like to listen to, and I kind of want to just have an option for 'surprise me!'. I can change the file names if I have to, and I have a basic batch file ability. I know the simple commands,...
General Discussion
How to run a batch file at logoff & some batch scripting help please
Hiya, I'd just like to run a simple batch file at logoff to backup some settings. I plan to use Robocopy, which is what i use to more thorough backups. Two questions: 1. How make it run by clicking Start > Shutdown? (i realise i could make a shutdown batch file and run it instead, but i'd...
Backup and Restore
Batch File that grabs file names from folder to insert into batch file
Ok I'm totally at a loss on how to word this so I'm just going to write it out the best that I can... :confused: First I have a batch file that I'm writing that will convert mp4 files to mp3 files (I have a lot) for a buddies band using ffmpeg. Here's the code that I'm using: ffmpeg -i...
General Discussion
batch file open file for program in the startup folder
I have a computer that is a drone specifically for an outside LED sign. This computer is designed to never shut off and doesn't have any other program on it besides Operating System and the sign software. I need to create a batch file that I can place in the "start-up" folder that will open the...
General Discussion
How to create a batch file that will move files based on the file type
How to create a batch file that will move files based on the file type? My Requirement : I need a batch file to copy all .doc files in all my HardDisk to a removable disk say (Z: drive) . Can anyone make it possible using a batch file?Please...Its urgent...
General Discussion


Our Sites

Site Links

About Us

Find Us

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

All times are GMT -5. The time now is 00:28.
Twitter Facebook Google+ Seven Forums iOS App Seven Forums Android App