Solved: Don't understand xcopy in CMD

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

jpboyrox

Thread Starter
Joined
Nov 22, 2009
Messages
344
I keep trying this:
xcopy PTC "D:\Users\USERNAME\Desktop\

but it keep s returning no files copied.
Why is that?
 

jpboyrox

Thread Starter
Joined
Nov 22, 2009
Messages
344
obviously i am putting in my username where it says USERNAME
 
Joined
Aug 7, 2007
Messages
9,028
Is it also saying File not found - PTC?
I'm assuming there is a closing double quote after the \, or you'd get a Parse error.
 

jpboyrox

Thread Starter
Joined
Nov 22, 2009
Messages
344
No. It is saying the following:

D:\Users\Josh\Desktop\Josh's Documents\My Downloads>xcopy PTC "D:\Users\Josh\Desktop\Josh's Documents\My Videos"
0 File(s) copied

The folder is there and has files and folders in it but won't copy
 
Joined
Aug 7, 2007
Messages
9,028
So you are trying to copy this folder:
D:\Users\Josh\Desktop\Josh's Documents\My Downloads\PTC
to here:
"D:\Users\Josh\Desktop\Josh's Documents\My Videos"

The Xcopy command you are using will only copy the files in the top level of the PTC folder. If will not copy any folders that are in the PTC folder, or the files they contain.
Does the PTC folder have files in it's top level?
What does a Dir PTC command show?
 

jpboyrox

Thread Starter
Joined
Nov 22, 2009
Messages
344
So you are trying to copy this folder:
D:\Users\Josh\Desktop\Josh's Documents\My Downloads\PTC
to here:
"D:\Users\Josh\Desktop\Josh's Documents\My Videos"

The Xcopy command you are using will only copy the files in the top level of the PTC folder. If will not copy any folders that are in the PTC folder, or the files they contain.
Does the PTC folder have files in it's top level?
What does a Dir PTC command show?
ah, well there's my problem. There are no files on the top level, only folders containing files themselves. How can I copy the entire folder, in the same way that right-click -> copy would? Also how can I delete an entire folder?

dir PTC returns the following:

Directory of D:\Users\Josh\Desktop\Josh's Documents\My Downloads\ptc

05/04/2010 00:31 <DIR> .
05/04/2010 00:31 <DIR> ..
05/04/2010 00:31 <DIR> ProDESKTOP 8.0
0 File(s) 0 bytes
3 Dir(s) 953,693,806,592 bytes free
 
Joined
Aug 7, 2007
Messages
9,028
You can get help on most commands in the command prompt by typing the command followed by /?
Xcopy /? for example:
Code:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\>xcopy /?
Copies files and directory trees.

XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]
                           [/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U]
                           [/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z]
                           [/EXCLUDE:file1[+file2][+file3]...]

  source       Specifies the file(s) to copy.
  destination  Specifies the location and/or name of new files.
  /A           Copies only files with the archive attribute set,
               doesn't change the attribute.
  /M           Copies only files with the archive attribute set,
               turns off the archive attribute.
  /D:m-d-y     Copies files changed on or after the specified date.
               If no date is given, copies only those files whose
               source time is newer than the destination time.
  /EXCLUDE:file1[+file2][+file3]...
               Specifies a list of files containing strings.  Each string
               should be in a separate line in the files.  When any of the
               strings match any part of the absolute path of the file to be
               copied, that file will be excluded from being copied.  For
               example, specifying a string like \obj\ or .obj will exclude
               all files underneath the directory obj or all files with the
               .obj extension respectively.
  /P           Prompts you before creating each destination file.
  /S           Copies directories and subdirectories except empty ones.
  [COLOR=Red][B]/E           Copies directories and subdirectories, including empty ones.[/B][/COLOR]
               Same as /S /E. May be used to modify /T.
  /V           Verifies each new file.
  /W           Prompts you to press a key before copying.
  /C           Continues copying even if errors occur.
  /I           If destination does not exist and copying more than one file,
               assumes that destination must be a directory.
  /Q           Does not display file names while copying.
  /F           Displays full source and destination file names while copying.
  /L           Displays files that would be copied.
  /G           Allows the copying of encrypted files to destination that does
               not support encryption.
  /H           Copies hidden and system files also.
  /R           Overwrites read-only files.
  /T           Creates directory structure, but does not copy files. Does not
               include empty directories or subdirectories. /T /E includes
               empty directories and subdirectories.
  /U           Copies only files that already exist in destination.
  /K           Copies attributes. Normal Xcopy will reset read-only attributes.
  /N           Copies using the generated short names.
  /O           Copies file ownership and ACL information.
  /X           Copies file audit settings (implies /O).
  /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.
  /Z           Copies networked files in restartable mode.

The switch /Y may be preset in the COPYCMD environment variable.
This may be overridden with /-Y on the command line.

C:\>
So to copy a folder tree, use this:
Code:
Xcopy [COLOR=Red][B]/E[/B][/COLOR] PTC "D:\Users\Josh\Desktop\Josh's Documents\My Videos\"
 

jpboyrox

Thread Starter
Joined
Nov 22, 2009
Messages
344
You can get help on most commands in the command prompt by typing the command followed by /?
Xcopy /? for example:
Code:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\>xcopy /?
Copies files and directory trees.

XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]
                           [/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U]
                           [/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z]
                           [/EXCLUDE:file1[+file2][+file3]...]

  source       Specifies the file(s) to copy.
  destination  Specifies the location and/or name of new files.
  /A           Copies only files with the archive attribute set,
               doesn't change the attribute.
  /M           Copies only files with the archive attribute set,
               turns off the archive attribute.
  /D:m-d-y     Copies files changed on or after the specified date.
               If no date is given, copies only those files whose
               source time is newer than the destination time.
  /EXCLUDE:file1[+file2][+file3]...
               Specifies a list of files containing strings.  Each string
               should be in a separate line in the files.  When any of the
               strings match any part of the absolute path of the file to be
               copied, that file will be excluded from being copied.  For
               example, specifying a string like \obj\ or .obj will exclude
               all files underneath the directory obj or all files with the
               .obj extension respectively.
  /P           Prompts you before creating each destination file.
  /S           Copies directories and subdirectories except empty ones.
  [COLOR=Red][B]/E           Copies directories and subdirectories, including empty ones.[/B][/COLOR]
               Same as /S /E. May be used to modify /T.
  /V           Verifies each new file.
  /W           Prompts you to press a key before copying.
  /C           Continues copying even if errors occur.
  /I           If destination does not exist and copying more than one file,
               assumes that destination must be a directory.
  /Q           Does not display file names while copying.
  /F           Displays full source and destination file names while copying.
  /L           Displays files that would be copied.
  /G           Allows the copying of encrypted files to destination that does
               not support encryption.
  /H           Copies hidden and system files also.
  /R           Overwrites read-only files.
  /T           Creates directory structure, but does not copy files. Does not
               include empty directories or subdirectories. /T /E includes
               empty directories and subdirectories.
  /U           Copies only files that already exist in destination.
  /K           Copies attributes. Normal Xcopy will reset read-only attributes.
  /N           Copies using the generated short names.
  /O           Copies file ownership and ACL information.
  /X           Copies file audit settings (implies /O).
  /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.
  /Z           Copies networked files in restartable mode.

The switch /Y may be preset in the COPYCMD environment variable.
This may be overridden with /-Y on the command line.

C:\>
So to copy a folder tree, use this:
Code:
Xcopy [COLOR=Red][B]/E[/B][/COLOR] PTC "D:\Users\Josh\Desktop\Josh's Documents\My Videos\"
Thanks a lot. I actually did that but obviously didn't read through it carefully enough
 

jpboyrox

Thread Starter
Joined
Nov 22, 2009
Messages
344
Perhaps I should create a new article for this, I will if I receive no replies but why does this not work:
if %delete%==y goto y
if %delete%==n goto n

:y
cls
rd /s/q PTC
cls
echo Files Deleted!
pause

:n
cls
echo Files not deleted
pause

If 'n' is selected it skips :y but if 'y' is selected it runs :y and then :n
Why is that and how can i sort it out?
 
Joined
Aug 7, 2007
Messages
9,028
After the pause at the end of the :y section, it continues with the next line in the file. You need a goto after the y section, just before the :n label, to go around the :n section.
Code:
if %delete%==y goto y
if %delete%==n goto n
 
:y
cls 
rd /s/q PTC
cls
echo Files Deleted!
pause
[COLOR=Red]Goto :skip[/COLOR]
:n
cls
echo Files not deleted
pause

:skip
Or make each section part of the If statement:
Code:
if %delete%==y (
    :y
    cls
    rd /s/q PTC
    cls
    echo Files Deleted!
    pause
)
if %delete%==n (
    :n
    cls
    echo Files not deleted
    pause
)
The parentheses act as a Line Continuation character, so the above is actualy seen as just 2 lines:
Code:
if %delete%==y cls&(rd /s/q PTC)&cls&(echo Files Deleted!)&pause
if %delete%==n cls&(echo Files not deleted)&pause
 

Squashman

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786

jpboyrox

Thread Starter
Joined
Nov 22, 2009
Messages
344
After the pause at the end of the :y section, it continues with the next line in the file. You need a goto after the y section, just before the :n label, to go around the :n section.
Code:
if %delete%==y goto y
if %delete%==n goto n
 
:y
cls 
rd /s/q PTC
cls
echo Files Deleted!
pause
[COLOR=Red]Goto :skip[/COLOR]
:n
cls
echo Files not deleted
pause

:skip
Or make each section part of the If statement:
Code:
if %delete%==y (
    :y
    cls
    rd /s/q PTC
    cls
    echo Files Deleted!
    pause
)
if %delete%==n (
    :n
    cls
    echo Files not deleted
    pause
)
The parentheses act as a Line Continuation character, so the above is actualy seen as just 2 lines:
Code:
if %delete%==y cls&(rd /s/q PTC)&cls&(echo Files Deleted!)&pause
if %delete%==n cls&(echo Files not deleted)&pause
Do the parentheses always do this, even if I am not using this command?
 
Joined
Aug 7, 2007
Messages
9,028
For the most part. It can't be used in the middle of a command though, only between commands. And Echo statements have to be enclosed in parentheses so the command processor knows where the Echo command ends.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Members online

Top