Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 457
  • Last Modified:

Bat script to copy a file to all folders in a directory

Hi all,

I need a .Bat script to copy a file to all folders in a directory

e.g.

Copy "C:\app.mdb" "C:\All folders in the C:\ directory"

There are about 40 folders under the c:\ dir.
0
joe90kane
Asked:
joe90kane
  • 2
  • 2
1 Solution
 
oBdACommented:
Open a command prompt at the root of C:, run this batch (it will exclude your Windows folder from the folders the file should be copied to):
@echo off
for /d %%a in (*.*) do (
  if /i not "%%a"=="%Systemroot%" copy C:\app.mdb "%%a"
)
0
 
joe90kaneAuthor Commented:
Thanks for that oBdA it works great, before I accept the answer would you be so kind to explain the script

/d =
/i =

etc...

Thanks again.
0
 
oBdACommented:
"for /d ..." will run the "for" loop only for *d*irectories, not for files (enter "help for" for more possibilities).
"if /i ..." will run the comparison case *i*nsensitive, otherwise "Windows" and "WINDOWS" would be different.
0
 
joe90kaneAuthor Commented:
Thanks for the info.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now