Solved

Move directory using batch file

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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 …
#Citrix #POC #XenDesktop #vCenter #VMware #ESX
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 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

17 Experts available now in Live!

Get 1:1 Help Now