Do you want to copy into a directory only if there are no files in that directory, or only if there are no files or sub directories in it?
~bp
Main Topics
Browse All TopicsHaving trouble with using the for /f statement.
Have tried to use a script I found to remove empty directories, but instead of deleting the directory I want to copy a text file from the root into the empty directory.
Original Script - Delete empty directories -
for /f "tokens=*" %%d in ('dir /ad/b/s ^| sort /R') do rd "%%d"
My script - to find empty directories and copy a txt file into it
for /f "tokens=*" %%d in ('dir /ad/b/s ^| sort /R') do copy readme.txt "%%d"
Problem is when I run this script, the readme.txt file is copied to every directory even when the directory is not empty in which I don't want. The readme.txt should only be copied to empty directories.
I am not too sure if this will also copy a readme.txt file to directories that have no files in but does have existing directories?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Sorry, attached file got blacked due to extension, here's the solution I wanted to attach to prior post, let me know how this works for you. It currently only copies the file to directories that don't contain any files, or other sub-directories. Adjust as needed. I also assumed you wanted to recursively look in all directories under some parent directory, hope I got that right.
~bp
Business Accounts
Answer for Membership
by: LeeeRussellPosted on 2009-11-02 at 03:32:13ID: 25718505
Hi
e.com/OS/ M icrosoft_O perating_S ystems/MS_ DOS/Q_2273 2091.html
I think your problem lies in the original batch file. This does not check for empty directories. RD will only delete empty directories, so a list of ALL directories is supplies to it and RD will only delete the empty ones.
This page: http://www.experts-exchang
gives a description of how to check for empty directories. Once you have that list you can use it to copy the file you need to empty directories only.
HTH,
Lee Russell