One of my friends had a problem about his aging portable usb Terabyte (1Tb = 1000Gb) hard drive. According to him, the portable usb sata hard drive was not detected in Windows XP and Windows Vista. Luckily, it was able to access under DOS.
So, one of the ways to do is to use xcopy to retrieve some important documents and transfer to another location and suggest him to buy a new hard drive too.
Let us look at xcopy syntax:
Xcopy (From Microsoft Technet)
Copies directories, their subdirectories, and files (except hidden and system files).With this command, you can copy all the files in a directory, including the files in the subdirectories of that directory.
Syntax
xcopy source [destination] [/a|/m] [/d:date] [/p] [/s [/e]] [/v] [/w]Parameters
source
Specifies the location and names of the files you want to copy. Source must include either a drive or a path.
destination
Specifies the destination of the files you want to copy. Destination can include a drive letter and colon, a directory name, a filename, or a combination.
Switches
/a
Copies only source files that have their archive file attributes set. This switch does not modify the archive file attribute of the source file. For information about how to set the archive file attribute, see the attrib command.
/m
Copies source files that have their archive file attributes set. Unlike the /a switch, the /m switch turns off archive file attributes in the files specified in source. For information about how to set the archive file attribute, see the attrib command.
/d: date
Copies only source files modified on or after the specified date. Note that the format of date depends on the country setting you are using.
/p
Prompts you to confirm whether you want to create each destination file.
/s
Copies directories and subdirectories, unless they are empty. If you omit this switch, xcopy works within a single directory.
/e
Copies any subdirectories, even if they are empty. You must use the /s switch with this switch.
/v
Verifies each file as it is written to the destination file to make sure that the destination files are identical to the source files.
/w
Displays the following message and waits for your response before starting to copy files:
Press any key to begin copying file(s)Notes
Default value for destination
If you omit destination, the xcopy command copies the files to the current directory.
Specifying whether destination is a file or directory
If destination does not contain an existing directory and does not end with a backslash (\), xcopy prompts you with a message in the following format:
Does destination specify a file name or directory name on the target (F = file, D = directory)?Press F if you want the file(s) to be copied to a file. Press D if you want the file(s) to be copied to a directory.
Xcopy does not copy hidden and system files
In older versions of MS-DOS, xcopy copies hidden and system files. This is not the case in MS-DOS 6. To remove the hidden or system attribute from a file, use the attrib command.
Xcopy sets archive attribute for destination files
Xcopy creates files with the archive attribute set, whether or not this attribute was set in the source file. For more information about file attributes, see the attrib command.
Xcopy vs. diskcopy
If you have a disk that contains files in subdirectories and you want to copy it to a disk that has a different format, you should use the xcopy command instead of diskcopy. Since the diskcopy command copies disks track by track, it requires that your source and destination disks have the same format. Xcopy has no such requirement. In general, use xcopy unless you need a complete disk image copy. However, xcopy will not copy hidden or system files such as IO.SYS and MSDOS.SYS. Therefore, use diskcopy to make copies of system disks.
Xcopy exit codes
The following list shows each exit code and a brief description of its meaning:
0 | Files were copied without error. |
1 | No files were found to copy. |
2 | The user pressed CTRL+C to terminate xcopy. |
4 | Initialization error occurred. There is not enough memory or disk space, or you entered an invalid drive name or invalid syntax on the command line. |
5 | Disk write error occurred. |
The following example copies all the files and subdirectories (including any empty subdirectories) from the disk in drive A to the disk in drive B:
xcopy a: b: /s /eThe following example uses the /d: and /v switches:
xcopy a: b: /d:01/18/93 /s /vIn this example, only files on the disk in drive A that were written on or after 01/18/93 are copied to the disk in drive B. Once the files are written to the disk in drive B, the xcopy command compares the files on the two disks to make sure they are the same.
You can create a batch program to perform xcopy operations and use the batch if command to process the exit code in case an error occurs. For example, the following batch program uses replaceable parameters for the xcopy source and destination parameters:
\@echo off rem COPYIT.BAT transfers all source rem files in all directories on the source rem drive (\%1) to the destination drive (\%2) xcopy \%1 \%2 /s /e if errorlevel 4 goto lowmemory if errorlevel 2 goto abort if errorlevel 0 goto exit\:lowmemory echo Insufficient memory to copy files or echo invalid drive or command-line syntax. goto exit\:abort echo You pressed CTRL+C to end the copy operation. goto exit\:exitTo use this batch program to copy all files in the C:\PRGMCODE directory and its subdirectories to drive B, type the following command:
copyit c:\prgmcode b:The command interpreter substitutes C:\PRGMCODE for %1 and B: for %2, then uses xcopy with the /e and /s switches. If xcopy encounters an error, the batch program reads the exit code and goes to the label indicated in the appropriate if errorlevel statement. MS-DOS displays the appropriate message and exits from the batch program.
- wong chee tat :)
No comments:
Post a Comment