Jump to content

Recommended Posts

Posted

I am after a batch program or a Powershell script that runs from variables from a user input screen. Basically a user has a folder of work and needs to copy this to a folder (that changes each week so not always the same hence the asking of Source and Destination) for a backup. From the supplied batch code I have so far got the user to input the source and the destination and it copies this to the destination and works.

 

My question is can this be run a scheduled task after the use has entered the information in? At the moment the user enters the source and destination in and it will backup at that time. Due to network activity and the computer it's running from, I wish to have this run at a later time/date when the network is less busy.

 

Is it possible for someone to enter in the source and destination and then these variables are then written to a text file to hold the paths and then another batch or Powershell then does the copy of the folder and reads from the textfile the source and destination it needs to copy to and from?

Hope this makes sense?

Batchfile

 

@echo off

::Ask

echo Enter Source Directory to copy :

set SRC=

set /P SRC=Type input: %=%

 

echo Enter Destination Directory to paste :

set DEST=

set /P DEST=Type input: %=%

 

xcopy /s /e /y %SRC% %DEST%

Posted

If this is one user on a machine, just set a separate batch file with the last line in, as a scheduled task.

 

If it’s multiple users on pc/network you need to log your src/dest to a file, probably .csv, and schedule to read the csv and process one by one.

 

Power shell will be easier.

Posted (edited)

You could do something like this:

 @[u][url="http://www.edugeek.net/member.php?u=16971"]echo[/url][/u] off::Ask
echo Enter Source Directory to copy :
set SRC=
set /P SRC=Type input: %=%
echo Enter Destination Directory to paste :
set DEST=
set /P DEST=Type input: %=%xcopy /s /e /y %SRC% %DEST% >> copy.bat

schtasks /CREATE /TN "Copy Files" /TR "C:\copy.bat" /ST 21:00 /F

It should create a batch file with the xcopy command with the source and destination locations, and then create a scheduled task that runs at 9pm that will run the xcopy batch file.

Edited by Knil92
  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...