Batch file


  1. Posts : 544
    Windows 10 Home, 64 bit
       #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 Computer


  2. Posts : 521
    Windows 7 Ultimate x64 Service Pack 1
       #2

    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


  3. Posts : 6,305
    Windows 7 Ultimate x64
       #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 Computer


  4. Posts : 521
    Windows 7 Ultimate x64 Service Pack 1
       #4

    Orbital Shark said:
    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 Computer


  5. Posts : 544
    Windows 10 Home, 64 bit
    Thread Starter
       #5

    OK, OS. Great idea. I'll try that. Thanks.
    And thanks oreo27. That might also work.
      My Computer


  6. Posts : 521
    Windows 7 Ultimate x64 Service Pack 1
       #6

    gogreen said:
    OK, OS. Great idea. I'll try that. Thanks.
    And thanks oreo27. That might also work.
    No problem mate! Cheers!
      My Computer


  7. Posts : 544
    Windows 10 Home, 64 bit
    Thread Starter
       #7

    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 Computer


  8. Posts : 521
    Windows 7 Ultimate x64 Service Pack 1
       #8

    gogreen said:
    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 Computer


  9. Posts : 544
    Windows 10 Home, 64 bit
    Thread Starter
       #9

    oreo27 said:
    gogreen said:
    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 Computer


 

  Related Discussions
Our Sites
Site Links
About 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 03:21.
Find Us