We help IT Professionals succeed at work.

Copying specific folder via batch file

Hi,

I'm new to scripting and I'm hoping someone can assist with the below required tasks:

I need to copy the below folder from C drive into F drive partition and if possible automate the copying using the Windows Task Scheduler

\Genie

I just need a batch file that I can use to fullfil the above required task.

Appreciate your generous help.
Comment
Watch Question

Top Expert 2013

Commented:
Why do you need a script? right click on the folder and select copy then right click on the f:drive and select past.

Or if you want to move it without keeping a copy in the current location just drag and drop the folder on the f: drive



Cd&

Author

Commented:
For backup purpose then automate it through Windows Task Scheduler.

Commented:

Hello mcse2007,

I can show you a BATCH DOS script to do that. So this is an example.

This code put in a file with extension .BAT. This is an example and click on .BAT file.

@echo off
echo.
echo.

F:

cd \

md "F:\My Computer\Favorites"

xcopy "C:\Documents and Settings\KORISNIK\Favorites\*.*" "F:\My Computer\Favorites" /S/E/Y


echo. All IE Favorites are copied to F: disk !!!
echo.
echo. The end of the job!!!
echo. Please press the any key on the keyboard to close this window !
echo.
pause

Open in new window


For eventually explanation ask me free.

Nrisimha

Commented:

So for your folder C:\Genie you have this code for BAT script:

@echo off
echo.
echo.

F:

cd \

md "F:\Genie"

xcopy "C:\Genie\*.*" "F:\Genie" /S/E/Y


echo. All files from C:\Genie are copied to F:\Genie disk !!!
echo.
echo. The end of the job!!!
echo. Please press the any key on the keyboard to close this window !
echo.
pause

Open in new window


Nrisimha
Top Expert 2013

Commented:

Author

Commented:
Hi Nrisimha,

The /S copy, the /E copy empty folder, what's the /Y ?

Cheers
Commented:

Well, XCOPY command has many options. But I will answer to you on your question:

 /S           Copies directories and subdirectories except empty ones.

 /E           Copies directories and subdirectories, including empty ones.
                         Same as /S /E. May be used to modify /T.

So I use /S/E !!!

 /Y           Suppresses prompting to confirm you want to overwrite an
                          existing destination file.


I want to give you an advice if you want that your script works without a asking to press any key to close the window.

In such a case use only this code:

@echo off

F:
cd \
md "F:\Genie"
xcopy "C:\Genie\*.*" "F:\Genie" /S/E/Y

Open in new window



If there are any questions, here I am:))

Nrisimha
Bill PrewTest your restores, not your backups...
Expert of the Year 2019
Top Expert 2016

Commented:
@mcse2007

If this is a backup need, what will happen the 2nd time this runs?  Will the destination folder exist from last backup, and do you want to overwrite?  If that is the case and you want a mirror of the live source folder, then robocopy with the /MIR option is probably the most appropriate.

As far as how to set up a job to run in the task scheduler just google for that and there are many good descriptions of that process available.

~bp
Top Expert 2013

Commented:
This will help you set it up  TASKS



Cd&

Commented:

Well, if anybody need Windows Command Reference - Windows 7/2008 then you can download a CHM file from:

http://www.microsoft.com/download/en/details.aspx?displaylang=en&=tm&id=2632

Nrisimha

Author

Commented:
Thanks for your help Nrisimha.

With your approach and attitude in solving problem, in no time, you will gain prominence here in EE. Well done mate and thanks for your help.

Commented:

Thank you mcse2007,

But I have to write something. If you want to enable Backup with an Genie folder that already exists on F: drive then use the next code:

@echo off

move "F:\Genie" "F:\Genie1"
md "F:\Genie"
xcopy "C:\Genie\*.*" "F:\Genie" /S/E/Y
rd "F:\Genie1" /S/Q

Open in new window



Nrisimha