0

I'm trying to make a batch file through Notepad to essentially automate a process of moving files from drive to drive.

My aim is to move files from my H drive to my A drive, H:\Arco\examplefile.csv to \A:\DSE\Open_Access_Data\ARCo.

I also want to automate this job to run every 30 minutes if possible. But if I need to do it by clicking it then so be it. So far, all I've managed to do is copy files over to my desktop. I can't seem to get it to go between my directories.

COPY H:\dehpc14_Disk_Quota_Report.csv %userprofile%\Desktop
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Zenaphor
  • 711
  • 5
  • 13
  • 21

2 Answers2

1

This should work:

:LOOP
copy H:\Arco\examplefile.csv A:\DSE\Open_Access_Data\ARCo /y
timeout /t 1800
goto :LOOP

That will copy your files every 30 seconds and overwrite any existing files.

Note: The timeout command is only availble in Vista and above, if you need to use this on XP let me know.

To launch the batch file on system startup you can either put it in the startup folder of the user or use the registry.

The startup folder for the current user is

C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

For all users

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup

Or you can use the registry which I personally prefer. Create a string value with the path to your batch file in

Current user

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run

Computer users

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

Both registry options will require admin rights though.

To do either startup or registry in batch respectively

copy %0 "C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup" /y

reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v "MyBatchFile" /d "%0" /f

Which will either copy itself to startup or add itself to the registry each time it runs. So you can either do it manually or have it do this itself (above commands) from the first time you run it.

The %0 is the batch files own path, if you want to use the commands from somewhere else, or just from cmd then type in the full path of the batch file instead.

Bali C
  • 28,049
  • 34
  • 109
  • 147
  • Thanks very much for th above example, works great, is there a way I can get it to run whenever the systems on or would it be a case having to start off the batch file each time? Thanks Z – Zenaphor Jun 26 '12 at 07:14
  • @Zenaphor No problem. I have edited my answer with info on how to start it on each log on. – Bali C Jun 26 '12 at 08:01
  • 1
    I prefer `%HOMEPATH%` and `%ALLUSERSPROFILE%`, as your fixed paths of `C:\Users\%username%` and `C:\ProgramData\...` only works on an english standard installation of newer windows versions – jeb Jun 26 '12 at 08:02
  • @jeb Yeah that would be better, but I was just typing in a hurry :) – Bali C Jun 26 '12 at 12:37
0

Use a command like cron in Unix to setup a timed interval to run programs like your automated copy. See Stack Overflow question What is the Windows version of cron? for a cron-like version for Windows.

To copy from one drive to another use

copy filepath1 filepath2

where filepath1 is your H:\path-to-file and filepath2 is your A:\path-to-file.

Community
  • 1
  • 1
Dexter Huinda
  • 1,252
  • 1
  • 7
  • 9