Page 1 of 1

Populate multiple folders with a particular file?

Posted: 02 Nov 2009 18:06
by elcoyoteloco
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.

Posted: 03 Nov 2009 12:36
by avery_larry

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"

Posted: 03 Nov 2009 15:54
by elcoyoteloco
I'll try it tonight. Thanks :)

UPDATE: That worked. Thanks again!

Posted: 07 Nov 2009 15:44
by elcoyoteloco
Follow-up question: Is there a way to have it copy ONLY to folders that don't already have the file?

Thanks

Posted: 07 Nov 2009 21:12
by avery_larry
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"

Posted: 08 Nov 2009 15:46
by elcoyoteloco
I'll give it try. Thanks!