Solved

Move directory using batch file

Posted on 2006-07-21
4
2,120 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Hello I read in a discussion about a person who configured a very simple mirror RAID with two hard drives; the system and data were on the same partition. He asked how to repair the system as it was not booting up anymore. In his case running …
I don't know if many of you have made the great mistake of using the Cisco Thin Client model with the management software VXC. If you have then you are probably more then familiar with the incredibly clunky interface, the numerous work arounds, and …
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now