Populate multiple folders with a particular file?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
elcoyoteloco
Posts: 4
Joined: 02 Nov 2009 17:50

Populate multiple folders with a particular file?

#1 Post by elcoyoteloco » 02 Nov 2009 18:06

Hi all, this is my first post on this forum.

I need to populate about 200 folders with the same file. I googled but couldn't find anything on this, so I'm hoping there's a way to do it using batch commands. Otherwise I'll need to browse to each folder individually and paste the file into them, which will take a lot of time.

Thanks :)

PS:

The file I want to add is ".directory". It tells XP what image to use (i.e. "folder.jpg")when a folder is viewed as a thumbnail. I'm using it for my music collection.

If you want to try this, just create a txt file with this text:
[Desktop Entry]
Icon=./folder.jpg (you can also use png images)

Rename it ".directory" and put it in the same folder as an album's mp3's and album cover. Go to that folder's parent and switch to thumbnail view, and the album cover should display. Pretty cool.

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#2 Post by avery_larry » 03 Nov 2009 12:36

Code: Select all

set "file=c:\path to\your file\.directory"
set "parentdir=c:\path to\the parent folder"

cd /d "%parentdir%"
for /d /r %%a in (*) do copy "%file%" "%%a"

elcoyoteloco
Posts: 4
Joined: 02 Nov 2009 17:50

#3 Post by elcoyoteloco » 03 Nov 2009 15:54

I'll try it tonight. Thanks :)

UPDATE: That worked. Thanks again!

elcoyoteloco
Posts: 4
Joined: 02 Nov 2009 17:50

#4 Post by elcoyoteloco » 07 Nov 2009 15:44

Follow-up question: Is there a way to have it copy ONLY to folders that don't already have the file?

Thanks

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#5 Post by avery_larry » 07 Nov 2009 21:12

Well, by default it will not overwrite -- so in essence it'll only copy if it doesn't exist. You can use

copy "%file%" "%%a" >nul 2>nul

to supress any errors. If you really want to exclude directories that already have the file, then:

Code: Select all

set "fdir=c:\path to\your file
set "fname=.directory"
set "parentdir=c:\path to\the parent folder"

cd /d "%parentdir%"
for /d /r %%a in (*) do if not exist "%%~a\%fname%" do copy "%fdir%\%fname%" "%%~a"

elcoyoteloco
Posts: 4
Joined: 02 Nov 2009 17:50

#6 Post by elcoyoteloco » 08 Nov 2009 15:46

I'll give it try. Thanks!

Post Reply