Creating Batch File in Dos

Posted on 2008-11-11
Last Modified: 2012-05-05
how can make a batch file script that can copy the 2 files in every dir including subdirectory...and one more thing is there a way how to install DOS 7.0 in windows xp so can use the deltree command...thanks!
Question by:zaldhie
    LVL 67

    Accepted Solution

    use rmdir instead of deltree

    batch file:
    @echo off
    for /r %%a in (.) do (
      copy c:\onefile.txt "%%a"
      copy c:\twofile.txt "%%a"

    Open in new window

    LVL 95

    Assisted Solution

    by:Lee W, MVP
    to expand on sirbounty's rmdir comment -

    rmdir and rd are essentially synonymous.

    RD /S will do the same thing deltree used to do.  For more information, just type RD /?
    LVL 7

    Assisted Solution

    These are the results of rd /?

    here is an example of this:

    rd /s /q f:temp\one      (This will delete folder one without asking you: are you sure (y/n)? It will dispose all the files and directories below it...)

    C:\Users\temp>rd /?                                                         Removes (deletes) a directory.                                                                                                                          RMDIR [/S] [/Q] [drive:]path                                                RD [/S] [/Q] [drive:]path                                                                                                                                   /S      Removes all directories and files in the specified directory                in addition to the directory itself.  Used to remove a directory            tree.                                                                                                                                           /Q      Quiet mode, do not ask if ok to remove a directory tree with /S

    Good luck.
    LVL 16

    Assisted Solution

    hiya zaldhie

    to answer both questions....and not wishing to step on either sirbounty's toes nor leew's toes...

    1) batch file to copy two files to every directory on the drive and log errors

    @echo off

    echo Could not copy files to the following directories: >LOGFILE

    for /r \ %%a in (.) do (
      echo Copying files to %%a

      copy FILE1 "%%a" >nul
      if not %errorlevel%==0 echo FILE1 %%a >>LOGFILE

      copy FILE2 "%%a" >nul
      if not %errorlevel%==0 echo FILE2 %%a >>LOGFILE

    notice the subtle difference in the second line. also, this batch file assumes FILE1 and FILE2 are in the same directorey as this batch file.

    after running the batch file you can examine the LOGFILE in notepad to determine where it was not permissible to copy either or both files FILE1 and FILE2.

    2) the DELTREE command was excluded from both Windows 2000 and Windows XP. instead, the internal RD command now includes the /S and /Q switches.

    the /S switch removes all sub-directories as well as the target directory.
    the /Q switch suppresses user confirmation prompts.

    the following command does what DELTREE did

    rd /s /q c:\DIRECTORY

    Author Comment

    thanks a lot guys!... i know where can i find a solution for my problem :P more power
    LVL 16

    Expert Comment

    Please be clearer and more specific with your question....

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
    Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    746 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

    18 Experts available now in Live!

    Get 1:1 Help Now