Perintah Copy Folder dengan menggunakan Command Prompt di Windows


Saya pernah mengalami suatu kasus pada saat akan melakukan copy data dari laptop yang rusak. Ketika saya mau copy data dari documents profil saya terdapat masalah tidak bisa di copy secara langsung melalui windows explorer dikarenaka masalah security, mungkin karena data pada folder documents tersebut berada pada profil user yang bertindak sebagai Administrator sehingga tidak bisa langsung di copy.

Kemudian dengan menggunakan command promt saya coba melakukan copy data tersebut yang berisi file dan folder dan berhasil. berikut saya share cara melakukan copy dari sebuah folder ke folder tertentu untuk mengatasi permasalahan yang dihadapi tersebut.

1. Buka command promt dengan cara Run as Administrator.
2. Kemudian pada command promt tersebut ketikan perintah:

xcopy c:\folderSumber c:\folderTujuan /s /e /h

3. Pada perintah diatas ganti "c:\folderSumber" dengan lokasi folder sumber yang akan di copy ke tempat atau folder lain.
4. Pada perintah diatas ganti c:\folderTujuan dengan lokasi folder tujuan yang akan di copy.
5. Dan jika tidak ada masalah maka folder dan file yang terdapat didalamnya yang sebelumnya tidak bisa dicopy dapat di salin ke folder lain.

Demikian semoga membantu. @wawanhn

Kemudian untuk lebih memahami perintah tersebut saya salin dari website http://ss64.com/nt/xcopy.html penjelasan detail tentang penggunaan perintah xcopy.

XCOPY
Copy files and/or directory trees to another folder. XCOPY is similar to the COPY command except that it has additional switches to specify both the source and destination in detail.
Xcopy has been deprecated under Vista and Windows 2008, this means that while still available now it might disappear in a future OS release. To ensure your scripts are 'future proof' use other tools (such as Robocopy) instead of xcopy.

XCOPY is particularly useful when copying files from CDROM to a hard drive, as it will automatically remove the read-only attribute.
Syntax
      XCOPY source [destination] [options]

Key
   source      : Pathname for the file(s) to be copied (accepts wildcards).

   destination : Pathname for the new file(s).
  
   [options] can be any combination of the following:
     
Source Options
     
   /A    Copy files with the archive attribute set (default=Y)

   /M    Copy files with the archive attribute set and
         turn off the archive attribute, use this option
         when making regular Backups (default=Y)
                                   
   /H    Copy hidden and system files and folders (default=N)

   /D:mm-dd-yyyy
         Copy files changed on or after the specified date.
         If no date is given, copy only files whose
         source date/time is newer than the destination time.

   /U    Copy only files that already exist in destination.
  
   /S    Copy folders and subfolders

   /E    Copy folders and subfolders, including Empty folders.
         can be used to modify /T.

   /EXCLUDE:file1[+file2][+file3]...

         The files can each contain one or more full or partial pathnames to be excluded.
         When any of these match any part of the absolute path of a SOURCE file, then
         that file will be excluded.
         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.
              
Copy Options
              
   /W    Prompt you to press a key before starting to copy.
   /P    Prompt before creating each file.

   /Y    Suppress prompt to confirm overwriting a file.
         can be preset in the COPYCMD env variable.
   /-Y   Prompt to confirm overwriting a file.
  
   /V    Verify that the new files were written correctly.
   /C    Continue copying even if an error occurs.
  
   /I    If in doubt always assume the destination is a folder
         e.g. when the destination does not exist.

   /B    Copy the Symbolic link itself, not the target of the file.

   /G    Allow the copying of encrypted files to a destination that does not support encryption.

   /J    Copy using unbuffered I/O. Recommended for very large files.
 
   /Q    Do not display file names while copying.
   /F    Display full source and destination file names while copying.
   /L    List only - Display files that would be copied.

   /Z    Copy files in restartable mode. If the copy is interrupted part way through,
         it will restart if possible. (use on slow networks)

Destination Options

   /R    Overwrite read-only files.

   /T    Create folder structure, but do not copy files.
         Do not include empty folders or subfolders.
          /T /E will include empty folders and subfolders.

   /K    Copy attributes. XCOPY will otherwise reset read-only attributes.

   /N    If at all possible, use only a short filename (8.3) when creating
         a destination file. This can be necessary when copying between disks
         that are formatted differently e.g NTFS and VFAT, or when archiving
         data to an ISO9660 CDROM.

   /O    Copy file Ownership and ACL information.

   /X    Copy file audit settings (implies /O).
XCOPY will accept UNC pathnames.
To always overwrite destination files use the COPYCMD environment variable: SET COPYCMD=/Y

When comparing Dates/Times the granularity (the finest increment of the timestamp) is 2 seconds for a FAT volume and 0.1 microsecond for an NTFS volume.
Copy a single file
In most cases copying a single file is best done with the COPY command. When copying a single file with XCOPY, there is no option to indicate if the destination is a filename or a directory (with the filename defaulting to that of the source file).
In such cases XCOPY will prompt with a (locale specific) message like:
 Does example.txt specify a file name
 or directory name on the target
 (F = file, D = directory)?
Insufficient Memory error
Attempting to XCOPY a source file that has a pathname longer than the Windows maximum path length (254 characters) will result in a rather misleading 'Insufficient Memory' error, the operation will then halt. This bug which has been around for over 10 years makes XCOPY a poor choice for any kind of backup script, use ROBOCOPY instead.
Examples:

Copy a file:

echo F| XCOPY C:\utils\MyFile.txt D:\Backup\CopyFile.txt

Copy a folder:

XCOPY C:\utils D:\Backup\utils /i

Copy a folder including all subfolders.

XCOPY C:\utils\* D:\Backup\utils /s /i
“It is easier to copy than to think, hence fashion” ~ Wallace Stevens

Related:

COPY - Copy one or more files to another location
DEL - Delete files
MOVE - Move a file from one folder to another
ROBOCOPY - Robust File and Folder Copy
PowerShell: Copy-Item - Copy an item from one location to another
Equivalent bash command (Linux): cp - Copy one or more files to another location


Previous
Next Post »
0 Komentar