copy files and create directories

copy files and create directories

I needed to come up with a solution to copy a directory/file to a specific location but I also needed to account for the fact that it might not be created so I needed it to also create the necessary folder structure and if the file existed I needed it to overwrite it.

This is the batch script I came up with

if not exist %appdata%\PROGRAM\settings mkdir %appdata%\PROGRAM\settings
copy "\\SERVER\SHARED\source" %appdata%\PROGRAM\settings /y
Code language: JavaScript (javascript)

Basically what the script is doing is checking C:\Users\USERNAME\AppData\Roaming\PROGRAM\settings to see if it exists if it doesn’t then it will create it. Next the script is copying the contents from the UNC path into the folder.

The way the script is currently written anything in the folder named source will get dumped into the settings folder in Roaming. If you need to copy just a specific file just add the specific file in the copy command and run it. For this solution I just set the script to be a Logon script via a GPO.

Leave a comment

Your email address will not be published. Required fields are marked *