Page 1 of 1

Need .bat file help

Posted: Sat Jan 12, 2019 6:52 pm
by jztemple2
It has been a long, long time since I've written .bat files :roll:

However, I've come across a situation where one might come in handy. I need to set up forty laptops for tax season and part of that is needing to copy two files, an HTML and a PDF, from a stick to the desktop and the C:/ drive location on each. These are Win10 machines. I used to remember how to do it, but old age has deprived me of this vital knowledge :grund: . Could someone come up with the code off the top of their head and post it? It's not a big deal if someone can't, my old, aged hands can just do drag and drop... :drool:

Re: Need .bat file help

Posted: Sat Jan 12, 2019 8:57 pm
by MonkeyFinger
Well... probably not much more than "copy" commands with maybe some "echo" commands thrown in to provide status messages.
COPY [/D] [/V] [/N] [/Y | /-Y] [/Z] [/L] [/A | /B ] source [/A | /B]
[+ source [/A | /B] [+ ...]] [destination [/A | /B]]

source Specifies the file or files to be copied.
/A Indicates an ASCII text file.
/B Indicates a binary file.
/D Allow the destination file to be created decrypted
destination Specifies the directory and/or filename for the new file(s).
/V Verifies that new files are written correctly.
/N Uses short filename, if available, when copying a file with a
non-8dot3 name.
/Y Suppresses prompting to confirm you want to overwrite an
existing destination file.
/-Y Causes prompting to confirm you want to overwrite an
existing destination file.
/Z Copies networked files in restartable mode.
/L If the source is a symbolic link, copy the link to the target
instead of the actual file the source link points to.

The switch /Y may be preset in the COPYCMD environment variable.
This may be overridden with /-Y on the command line. Default is
to prompt on overwrites unless COPY command is being executed from
within a batch script.

To append files, specify a single file for destination, but multiple files
for source (using wildcards or file1+file2+file3 format).
Probably won't need any of the optional switches. For the desktop, the path would be C:\Users\<username>\Desktop but case doesn't matter in Windows.

Re: Need .bat file help

Posted: Sat Jan 12, 2019 9:00 pm
by Victoria Raverna
Create a folder Source in the thumb drive.
Put the files you need to copy in the folder Source that you created.

Create a batch file (.bat) in the thumb drive root folder with the following content:
copy Source\*.* C:\ /Y
copy Source\*.* %UserProfile%\Desktop /Y

Eject the thumb drive.

Put the thumb drive in each of the 40 laptops and run the batch file.

BTW, if you want to do it old school, you can create the batch file from command prompt like this:

change current directory to the thumb drive root ( cd D:\ if the thumb drive is drive D )
copy con FILENAME.bat (Then Enter key)
copy Source\*.* C:\ Y (Then Enter key)
copy Source\*.* %UserProfile%\Desktop /Y (Then Enter key)
(Press Ctrl-Z key combination)


For the desktop location, if you want them to appear to all users instead of the current user, you can change the second copy line to copy to %PUBLIC%\Desktop instead of %UserProfile%\Desktop.

Re: Need .bat file help

Posted: Sat Jan 12, 2019 9:27 pm
by jztemple2
Awesome inputs, thanks! :wub:

At least it seems vaguely familiar :roll: