Copy Semua Isi Sub Folder Tanpa Menyertakan Folder atau Sub Foldernya

Struktur:

@echo off
title WAIT !

md path\derectory_folder_tujuan

Set "sourceDir=path\alamat_sumber"
Set "destinationFolder=path\alamat_tujuan"
Set "_report=d:\logxcopy.txt"

IF NOT EXIST "%sourceDir%" (echo.Could not find %sourceDir% &GoTo:done)

:: overwrite previous log
>"%_report%" (
      echo.%date% - %time%
      echo.---------------------------------------------------
      echo.
)

:: copy files
For /F "Delims=" %%! in ('Dir "%sourceDir%\" /b /s /a-d 2^>nul') do (
   @echo.%%! &(
   @xcopy "%%!" "%destinationFolder%\" /i /y /h /f /c >>"%_report%",2>&1)
)

:done
title, Done..


Keterangan:
Ganti path\alamat_sumber dengan alamat drive\folder file yang akan di-copy. Bisa antar jaringan/network. contoh:
D:\DATA FOTO
D:\DATA FOTO\2015
\\Pc1\02 foto 2014 (contoh path antar jaringan)

Ganti path\alamat_tujuan dengan alamat drive\folder yang akan dijadikan tempat hasil copy-an. Bisa antar jaringan/network.
contoh:
D:\DATA FOTO
D:\DATA FOTO\2015
\\Pc1\02 foto 2014 (contoh path antar jaringan)

syntax:  md path\derectory_folder_tujuan berfungsi untuk membuat folder tujuan baru. Jika folder tujuan sudah ada, syntax ini dihapus saja.

Dengan script ini, kita bisa melakukan perintah copy lebih dari 1 source. Misalnya kita ingin mengcopy semua file yang ada sub-sub folder berikut:


Pada D:\FOTO AREA\2014 dan D:\FOTO AREA\2015 masing-masing terdapat banyak sub-sub folder, kita ingin mengcopy file-file dalam folder D:\FOTO AREA\2014 dan D:\FOTO AREA\2015 ke dalam folder baru:
D:\FOTO AREA\2014_baru dan
D:\FOTO AREA\2015_baru
tanpa mengikutkan sub-sub folder, jadi hanya file-filenya saja yang kita copy. Di sini folder tujuan (misalnya) sudah kita buat/siapkan dulu, jadi syntax "md" kita hapus. Maka scripnya menjadi seperti di bawah ini:

@echo off
title WAIT !

Set "sourceDir=D:\FOTO AREA\2014"
Set "sourceDir2=D:\FOTO AREA\2015"
Set "destinationFolder=D:\FOTO AREA\2014_baru"
Set "destinationFolder2=D:\FOTO AREA\2015_baru"
Set "_report=d:\logxcopy.txt"

IF NOT EXIST "%sourceDir%" (echo.Could not find %sourceDir% &GoTo:done)
IF NOT EXIST "%sourceDir2%" (echo.Could not find %sourceDir% &GoTo:done)

:: overwrite previous log
>"%_report%" (
      echo.%date% - %time%
      echo.---------------------------------------------------
      echo.
)

:: copy files
For /F "Delims=" %%! in ('Dir "%sourceDir%\" /b /s /a-d 2^>nul') do (
   @echo.%%! &(
   @xcopy "%%!" "%destinationFolder%\" /i /y /h /f /c >>"%_report%",2>&1)
)

For /F "Delims=" %%! in ('Dir "%sourceDir2%\" /b /s /a-d 2^>nul') do (
   @echo.%%! &(
   @xcopy "%%!" "%destinationFolder2%\" /i /y /h /f /c >>"%_report%",2>&1)
)

:done
title, Done..


Sekian semoga bermanfaat..

Subscribe to receive free email updates:

0 Response to "Copy Semua Isi Sub Folder Tanpa Menyertakan Folder atau Sub Foldernya"

Posting Komentar