Need .bat file help

For general computer discussion & help, come here

Moderators: Bakhtosh, EvilHomer3k

Post Reply
User avatar
jztemple2
Posts: 11514
Joined: Fri Feb 13, 2009 7:52 am
Location: Brevard County, Florida, USA

Need .bat file help

Post 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:
My father said that anything is interesting if you bother to read about it - Michael C. Harrold
User avatar
MonkeyFinger
Posts: 3223
Joined: Thu Dec 30, 2004 10:23 pm
Location: South of Denver, CO

Re: Need .bat file help

Post 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.
-mf
User avatar
Victoria Raverna
Posts: 4964
Joined: Fri Oct 15, 2004 2:23 am
Location: Jakarta

Re: Need .bat file help

Post 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.
User avatar
jztemple2
Posts: 11514
Joined: Fri Feb 13, 2009 7:52 am
Location: Brevard County, Florida, USA

Re: Need .bat file help

Post by jztemple2 »

Awesome inputs, thanks! :wub:

At least it seems vaguely familiar :roll:
My father said that anything is interesting if you bother to read about it - Michael C. Harrold
Post Reply