Solved Batch file

gogreen

New member
Power User
VIP
Local time
5:00 PM
Messages
544
Location
Florida
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 Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dell Studio XPS 8100, Dell XPS 15 laptop
OS
Windows 10 Home, 64 bit
CPU
Intel Core i7 860 @ 2.8 GHz
Motherboard
Dell 0T568R (CPU1)
Memory
8.0 GB Dual Channel DDR3 @ 664 MHz (9-9-9-24)
Graphics Card(s)
nVidia GeForce GTS 240
Sound Card
M-Audio Delta Audiophile 2496
Monitor(s) Displays
Dell 2407WFP
Screen Resolution
1920x1200
Hard Drives
977 GB Western Digital WDC WD1001FAES-75W7A0 (SCSI)
Antivirus
Windows Defender, MalwareBytes Anti-Malware, AdwCleaner
Browser
Firefox, occasionally IE and Edge
Other Info
Mozilla Firefox, Mozilla Thunderbird. Western Digital Passport 250 GB external HD, two Mushkin Enhanced Mulholland 32GB USB flash drives, AKG K240 Studio headphones, Asus AC-1900 dual band wireless router.
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 Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom Build
OS
Windows 7 Ultimate x64 Service Pack 1
CPU
AMD Athlon II x4 Propus 2.9 GHz
Motherboard
ASRock N68C-GS FX
Memory
2 x 4GB Corsair XMS 3 DDR3 -1600 CL9
Graphics Card(s)
AMD Radeon HD 5850 1GB GDDR5
Sound Card
On-board 6-Channel HD Audio
Monitor(s) Displays
18' LG Flatron E1942TC-BN on DVI, 18' Chimei 95ND on HDMI
Screen Resolution
1366 x 768 x 2
Hard Drives
1 x 500 GB Seagate
1 x 1 TB Western Digital Caviar Green
1 x 1 TB Hitachi Touro Mobile USB 3
PSU
Seasonic S12II 520W
Case
Generic with Cable Management
Cooling
Deep Cool Gammaxx 200
Keyboard
Dragonwar Desert Eagle
Mouse
Logitech B85
Internet Speed
5Mb/s DL, 0.9Mb/s UL
Antivirus
ESET Nod32
Browser
Google Chrome 64 Bit
Other Info
LG G4 H818P - Rooted with Xposed Framework
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:
[COLOR=red]c:[/COLOR]
[COLOR=red]cd "documents and settings\all users\application data\microsoft\office\data"[/COLOR]
[COLOR=red]ren data.bak data.new[/COLOR]
[COLOR=red]cd\[/COLOR]
[COLOR=blue][insert delete code here][/COLOR]
[COLOR=red]c:[/COLOR]
[COLOR=red]cd "documents and settings\all users\application data\microsoft\office\data"[/COLOR]
[COLOR=#ff0000]ren data.new data.bak[/COLOR]
[COLOR=#ff0000]cd\[/COLOR]
It should then rename the file both before and after the delete script, keeping it intact.


OS
 

My Computer

Computer Manufacturer/Model Number
Compaq Desktop
OS
Windows 7 Ultimate x64
CPU
AMD Sempron Dual Core
Memory
3GB
Graphics Card(s)
NVIDIA GeForce 6150SE nForce 430
Screen Resolution
1024x768
Hard Drives
150GB Sata
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:
[COLOR=red]c:[/COLOR]
[COLOR=red]cd "documents and settings\all users\application data\microsoft\office\data"[/COLOR]
[COLOR=red]ren data.bak data.new[/COLOR]
[COLOR=red]cd\[/COLOR]
[COLOR=blue][insert delete code here][/COLOR]
[COLOR=red]c:[/COLOR]
[COLOR=red]cd "documents and settings\all users\application data\microsoft\office\data"[/COLOR]
[COLOR=#ff0000]ren data.new data.bak[/COLOR]
[COLOR=#ff0000]cd\[/COLOR]
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.:cry:
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom Build
OS
Windows 7 Ultimate x64 Service Pack 1
CPU
AMD Athlon II x4 Propus 2.9 GHz
Motherboard
ASRock N68C-GS FX
Memory
2 x 4GB Corsair XMS 3 DDR3 -1600 CL9
Graphics Card(s)
AMD Radeon HD 5850 1GB GDDR5
Sound Card
On-board 6-Channel HD Audio
Monitor(s) Displays
18' LG Flatron E1942TC-BN on DVI, 18' Chimei 95ND on HDMI
Screen Resolution
1366 x 768 x 2
Hard Drives
1 x 500 GB Seagate
1 x 1 TB Western Digital Caviar Green
1 x 1 TB Hitachi Touro Mobile USB 3
PSU
Seasonic S12II 520W
Case
Generic with Cable Management
Cooling
Deep Cool Gammaxx 200
Keyboard
Dragonwar Desert Eagle
Mouse
Logitech B85
Internet Speed
5Mb/s DL, 0.9Mb/s UL
Antivirus
ESET Nod32
Browser
Google Chrome 64 Bit
Other Info
LG G4 H818P - Rooted with Xposed Framework
OK, OS. Great idea. I'll try that. Thanks.
And thanks oreo27. That might also work.
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dell Studio XPS 8100, Dell XPS 15 laptop
OS
Windows 10 Home, 64 bit
CPU
Intel Core i7 860 @ 2.8 GHz
Motherboard
Dell 0T568R (CPU1)
Memory
8.0 GB Dual Channel DDR3 @ 664 MHz (9-9-9-24)
Graphics Card(s)
nVidia GeForce GTS 240
Sound Card
M-Audio Delta Audiophile 2496
Monitor(s) Displays
Dell 2407WFP
Screen Resolution
1920x1200
Hard Drives
977 GB Western Digital WDC WD1001FAES-75W7A0 (SCSI)
Antivirus
Windows Defender, MalwareBytes Anti-Malware, AdwCleaner
Browser
Firefox, occasionally IE and Edge
Other Info
Mozilla Firefox, Mozilla Thunderbird. Western Digital Passport 250 GB external HD, two Mushkin Enhanced Mulholland 32GB USB flash drives, AKG K240 Studio headphones, Asus AC-1900 dual band wireless router.

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom Build
OS
Windows 7 Ultimate x64 Service Pack 1
CPU
AMD Athlon II x4 Propus 2.9 GHz
Motherboard
ASRock N68C-GS FX
Memory
2 x 4GB Corsair XMS 3 DDR3 -1600 CL9
Graphics Card(s)
AMD Radeon HD 5850 1GB GDDR5
Sound Card
On-board 6-Channel HD Audio
Monitor(s) Displays
18' LG Flatron E1942TC-BN on DVI, 18' Chimei 95ND on HDMI
Screen Resolution
1366 x 768 x 2
Hard Drives
1 x 500 GB Seagate
1 x 1 TB Western Digital Caviar Green
1 x 1 TB Hitachi Touro Mobile USB 3
PSU
Seasonic S12II 520W
Case
Generic with Cable Management
Cooling
Deep Cool Gammaxx 200
Keyboard
Dragonwar Desert Eagle
Mouse
Logitech B85
Internet Speed
5Mb/s DL, 0.9Mb/s UL
Antivirus
ESET Nod32
Browser
Google Chrome 64 Bit
Other Info
LG G4 H818P - Rooted with Xposed Framework
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!:cool:
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dell Studio XPS 8100, Dell XPS 15 laptop
OS
Windows 10 Home, 64 bit
CPU
Intel Core i7 860 @ 2.8 GHz
Motherboard
Dell 0T568R (CPU1)
Memory
8.0 GB Dual Channel DDR3 @ 664 MHz (9-9-9-24)
Graphics Card(s)
nVidia GeForce GTS 240
Sound Card
M-Audio Delta Audiophile 2496
Monitor(s) Displays
Dell 2407WFP
Screen Resolution
1920x1200
Hard Drives
977 GB Western Digital WDC WD1001FAES-75W7A0 (SCSI)
Antivirus
Windows Defender, MalwareBytes Anti-Malware, AdwCleaner
Browser
Firefox, occasionally IE and Edge
Other Info
Mozilla Firefox, Mozilla Thunderbird. Western Digital Passport 250 GB external HD, two Mushkin Enhanced Mulholland 32GB USB flash drives, AKG K240 Studio headphones, Asus AC-1900 dual band wireless router.
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!:cool:

Well, at least you're satisfied now. Congratulations mate! :)
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom Build
OS
Windows 7 Ultimate x64 Service Pack 1
CPU
AMD Athlon II x4 Propus 2.9 GHz
Motherboard
ASRock N68C-GS FX
Memory
2 x 4GB Corsair XMS 3 DDR3 -1600 CL9
Graphics Card(s)
AMD Radeon HD 5850 1GB GDDR5
Sound Card
On-board 6-Channel HD Audio
Monitor(s) Displays
18' LG Flatron E1942TC-BN on DVI, 18' Chimei 95ND on HDMI
Screen Resolution
1366 x 768 x 2
Hard Drives
1 x 500 GB Seagate
1 x 1 TB Western Digital Caviar Green
1 x 1 TB Hitachi Touro Mobile USB 3
PSU
Seasonic S12II 520W
Case
Generic with Cable Management
Cooling
Deep Cool Gammaxx 200
Keyboard
Dragonwar Desert Eagle
Mouse
Logitech B85
Internet Speed
5Mb/s DL, 0.9Mb/s UL
Antivirus
ESET Nod32
Browser
Google Chrome 64 Bit
Other Info
LG G4 H818P - Rooted with Xposed Framework
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!:cool:

Well, at least you're satisfied now. Congratulations mate! :)

Yeah, thanks. Sometimes it takes a little thinking to come up with the obvious solution!:geek:
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dell Studio XPS 8100, Dell XPS 15 laptop
OS
Windows 10 Home, 64 bit
CPU
Intel Core i7 860 @ 2.8 GHz
Motherboard
Dell 0T568R (CPU1)
Memory
8.0 GB Dual Channel DDR3 @ 664 MHz (9-9-9-24)
Graphics Card(s)
nVidia GeForce GTS 240
Sound Card
M-Audio Delta Audiophile 2496
Monitor(s) Displays
Dell 2407WFP
Screen Resolution
1920x1200
Hard Drives
977 GB Western Digital WDC WD1001FAES-75W7A0 (SCSI)
Antivirus
Windows Defender, MalwareBytes Anti-Malware, AdwCleaner
Browser
Firefox, occasionally IE and Edge
Other Info
Mozilla Firefox, Mozilla Thunderbird. Western Digital Passport 250 GB external HD, two Mushkin Enhanced Mulholland 32GB USB flash drives, AKG K240 Studio headphones, Asus AC-1900 dual band wireless router.
Back
Top