Solved

Move directory using batch file

Posted on 2006-07-21
4
2,124 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

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 …
Just about everyone has an old PC laying around.  Ask anyone in the IT industry, whether they are a professional or play in it as a hobby.  From outdated Desktops to cheap "throwaway" laptops, they are all around and not as hard to "fix up" as you m…
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.

735 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