Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2150
  • Last Modified:

Move directory using batch file

I have a batch file that currently copies all the files and folders under one directory.

once the files are copied I want all the contents that were just copied to be deleted so that the parent directory is totally empty.

How do I do this?
0
vlahomt
Asked:
vlahomt
1 Solution
 
gbirkemeierCommented:
Look at xxcopy, I belive it has a move function.
http://www.xxcopy.com/index.htm

Also, you could pull a copy of deltree from an old Win9x system and add that to the end of the batch file.
http://www.easydos.com/deltree.html
0
 
Yancey LandrumTechnical Team LeadCommented:
In your batch file, add the following two lines:

rd /s /q <folder you want to empty>
md <folder you want to empty>
0
 
haim96Commented:
if you using XP or server 2000/2003
 you can use the MOVE command :
this is the help output for MOVE /? command:
***************************************

C:\Documents and Settings\Administrator>move /?
Moves files and renames files and directories.

To move one or more files:
MOVE [/Y | /-Y] [drive:][path]filename1[,...] destination

To rename a directory:
MOVE [/Y | /-Y] [drive:][path]dirname1 dirname2

  [drive:][path]filename1 Specifies the location and name of the file
                          or files you want to move.
  destination             Specifies the new location of the file. Destination
                          can consist of a drive letter and colon, a
                          directory name, or a combination. If you are moving
                          only one file, you can also include a filename if
                          you want to rename the file when you move it.
  [drive:][path]dirname1  Specifies the directory you want to rename.
  dirname2                Specifies the new name of the directory.

  /Y                      Suppresses prompting to confirm you want to
                          overwrite an existing destination file.
  /-Y                     Causes prompting to confirm you want to overwrite
                          an existing destination file.

The switch /Y may be present in the COPYCMD environment variable.
This may be overridden with /-Y on the command line.  Default is
to prompt on overwrites unless MOVE command is being executed from
within a batch script.

*****************************************************
0
 
timmay413Commented:
you can use the "xcopy" command to copy the directory and its contents to another location, then use the "del" command to erase the old stuff   ex:


xcopy "%USERPROFILE%\favorites" "h:\__%USERNAME%\favorites\"  /E /H /y
del .....your files and switches here.......
end


this has been tested back to nt4, as I used to upgrade pcs to xp with a script i wrote, this copied files. Obviously there is more code, this just demonstrates xcopy and how it works. the switches at the end of xcopy makes it overwrite duplicates, not prompt and answer yes to any questions
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now