Zenaphor
Zenaphor

Reputation: 801

Copy file and delete duplicates using Windows batch file

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

Upvotes: 0

Views: 3414

Answers (2)

Dexter Huinda
Dexter Huinda

Reputation: 1222

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.

Upvotes: 0

Bali C
Bali C

Reputation: 31251

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.

Upvotes: 1

Related Questions