Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 386
  • Last Modified:

Creating Batch File in Dos

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!
0
zaldhie
Asked:
zaldhie
4 Solutions
 
sirbountyCommented:
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

0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
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 /?
0
 
pr0t0c0l12Commented:
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.
0
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 
t0t0Commented:
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
 
0
 
zaldhieAuthor Commented:
thanks a lot guys!... i know where can i find a solution for my problem :P more power
0
 
t0t0Commented:
Please be clearer and more specific with your question....
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Tackle projects and never again get stuck behind a technical roadblock.
Join Now