Solved

Move directory using batch file

Posted on 2006-07-21
4
2,123 Views
Last Modified: 2008-01-09
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
Comment
Question by:vlahomt
4 Comments
 
LVL 4

Expert Comment

by:gbirkemeier
ID: 17154335
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
 
LVL 13

Accepted Solution

by:
ylandrum earned 300 total points
ID: 17154397
In your batch file, add the following two lines:

rd /s /q <folder you want to empty>
md <folder you want to empty>
0
 
LVL 13

Expert Comment

by:haim96
ID: 17154698
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
 

Expert Comment

by:timmay413
ID: 17154963
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes a user will call me frantically, explaining that something has gone wrong and they have tried everything (read - they have messed it up more and now need someone to clean up) and it still does no good, can I help them?!  Usually the standa…
#Citrix #POC #XenDesktop #vCenter #VMware #ESX
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question