Copy one file to seperate folder

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Artifact
Posts: 1
Joined: 10 Mar 2020 15:02

Copy one file to seperate folder

#1 Post by Artifact » 10 Mar 2020 15:10

<r>Hello guys, I'm new overhere so I got problem that I got about 1300 folder where I need to copy some licence file so I need some batch or something like that solution how to do that.<br/>
For example I got file in C:/licence.bin that i need to copy in<br/>
<br/>
C:/SomeFolder/<br/>
- Users<br/>
------ Joe<br/>
------------ Joe1<br/>
------------ Joe2<br/>
------------ Joe3<br/>
------ Kevin<br/>
------------ Kevin's_Son<br/>
------ MadMax<br/>
<br/>
and I want that licence.bin into last empty sub-folder of Users, like joe 1,2,3, Kevin's Son and MadMax <E>:)</E> Can someone give me some idea or solution?</r>

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Copy one file to seperate folder

#2 Post by dbenham » 10 Mar 2020 15:50

Please note that windows uses \ in paths, not /

Also, you should learn to use the markup language supported by this site - html does not work. The buttons at the top of the post editor work well, and are pretty self-evident.

The following one liner should do the trick from the command line

Code: Select all

for /r "c:\SomeFolder\Users" /d %F in (*) do @dir /b /ad "%F" | findstr "^" >nul || copy "c:\licence.bin" "%F" >nul
If you want the command in a batch script, then you must double the percents

Code: Select all

@echo off
for /r "c:\SomeFolder\Users" /d %%F in (*) do dir /b /ad "%%F" | findstr "^" >nul || copy "c:\licence.bin" "%%F" >nul
The above assumes that by "empty sub-folder" you mean a folder that does not contain any other folders, but may have files.

If you truly mean empty, (no files or folders), then remove the /ad option from the dir command


Dave Benham

Post Reply