batch for sub directories name take and copy to a file

Posted on 2014-08-08
Last Modified: 2014-08-09
Hello I have a directory c:\data with a lot of sub directories we want a script that look inside each sub directory for the file resources.html
   All sub directories contain a different resources.html because of that we want the batch.
   Now the batch once found the resource.html the script must copy that file resource.html but with the same of the sub directory name where its the main resources.html
   For example:
  In c:\data we have 2 sub directories c:\data\app2 and c:\data\app3 this is just an example because actually we have hundred of sub directories there.
  Now in our example like I mentioned each sub directory has its own resources.html it means something like that c:\data\app2\resources.html and c:\data\app3\resources.html and so on for hundred directories now the batch must copy each resources.html with the name of the sub directory where was taken and with same destination in other words the resulting copied files will be:
    c:\data\app2\app2.html and  c:\data\app3\app3.html note that app2.html and app3.html are the new files copied, the relation is: app2.html is the resources.html that correspond to sub directory c:\data\app2\resources.html and app3.html is the resources.html that corresponds to c:\data\app3\resources.html is like just copy the resources.html in the same directory but with name of the sub directory where it is its resources.html in other word and with destination in same sub directory and note also the name is just app2.html and app3.html and the name c:\data was ignored for each name of the new files; for c:\data\app2\ juts we take the app2 section to name the app2.html and ignore the c:\data and the similar for app3 and of course like we have hundred of sub directories with different names that will be the dame procedure for all.
I hope someone can help for a batch fo ms dos command prompt.
Thank you
Question by:coerrace
    LVL 43

    Accepted Solution

    Wow, what a long description... Think you just want this...

    @echo off
    CD /d c:\data
    For /f "tokens=*" %%a in ('dir /b /ad') do copy /y "%%~a\resources.html" "%%~a\%%~a.HTML"

    To do from cmd prompt rather than batch file change to the directory then do for command but each %% change to just %.


    Author Closing Comment

    Works perfect
    LVL 43

    Expert Comment

    by:Steve Knight
    NP, try typing that on a phone :-)


    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Report events not being triggered 8 67
    Office & Windows Activation with Email 3 38
    changePi Challenge 15 57
    Vbscript 7 35
    This article was inspired by a question here at Experts Exchange ( The requirements stated in that question are (1) reduce the file size of a large number of…
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now