Announcement

Collapse
No announcement yet.

Simple Bat question - Selectively delete files?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Simple Bat question - Selectively delete files?

    A quick question, perhaps my google search terms are wrong by I cannot seem to find what I am looking for. I am writing a bat script which will run at logon and copy all files from a users U drive to U drive while excluding all pst files and folders named outlook/windows. This part is fine.

    What I would then like to do is go back and recursively delete all the files moved except for those excluded in the original xcopy. I tried to do this by:
    Code:
    xcopy "M:\*.*" "U:\Old M Drive\" /s /EXCLUDE:T:\exclude.txt
    call "T:\remove.bat"
    where remove.bat is
    Code:
    for  %%G  in  (XCOPY /u/n/l/y/s "M:\" "U:\Old M Drive\")  do  del "%%G"
    This, however, does not delete any directories. Does anyone have any suggestions? This seems like it should be an easy function, however, I cannot find any exclude parameters.

  • #2
    Re: Simple Bat question - Selectively delete files?

    I believe robocopy will solve your problem. It can move files, and it can exclude stuff at the same time. If this is what you need to do, have a look at http://www.microsoft.com/technet/tec...t/default.aspx and download the UtilitySpotlight whic offers a GUI front end to Robocopy. This helps you to buld your batch file with the right switches, as there are so very many switches to use.
    Best wishes,
    PaulH.
    MCP:Server 2003; MCITP:Server 2008; MCTS: SBS2008

    Comment


    • #3
      Re: Simple Bat question - Selectively delete files?

      Thanks for the (privately sent) kind words - glad it's useful. Look at the /S and /MOV and /XD and /XF switches in particular. These should help you out.

      /S = do subdirectories as well
      /MOV = move the files so the originals get deleted
      /XD = exclude these folder names
      /XF = exlude these file names.

      The UtilitySpotlight makes sense of all these switches, there are lots more so it does all get rather confusing.
      Best wishes,
      PaulH.
      MCP:Server 2003; MCITP:Server 2008; MCTS: SBS2008

      Comment


      • #4
        Re: Simple Bat question - Selectively delete files?

        Looks like a great tool, I am playing with it now...can it be run on a client machine that does not have robocopy installed?

        Comment


        • #5
          Re: Simple Bat question - Selectively delete files?

          No, it cannot.

          But robocopy.exe is a stand-alone program that can be copied within a batch file to your users' PCs. The GUI interface simply helps you to create the command that robocopy needs to run. To make robocopy actually work, you do not need the GUI interface - just the command line tool which is robocopy.exe.

          Hope this helps.
          Best wishes,
          PaulH.
          MCP:Server 2003; MCITP:Server 2008; MCTS: SBS2008

          Comment

          Working...
          X