home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / alt / msdos / programm / 2187 < prev    next >
Encoding:
Internet Message Format  |  1992-08-12  |  2.7 KB

  1. Path: sparky!uunet!comp.vuw.ac.nz!waikato.ac.nz!canterbury.ac.nz!cctr132
  2. Newsgroups: alt.msdos.programmer
  3. Subject: Re: Need DOS batch help!
  4. Message-ID: <1992Aug13.130054.312@csc.canterbury.ac.nz>
  5. From: cctr132@csc.canterbury.ac.nz (Nick FitzGerald, CSC, Uni. of Canterbury, NZ)
  6. Date: 13 Aug 92 13:00:54 +1200
  7. References: <92225.09262732BFPQ3@CMUVM.CSV.CMICH.EDU> <1992Aug12.141526.25165@athena.mit.edu>
  8. Organization: University of Canterbury, Christchurch, New Zealand
  9. Lines: 57
  10.  
  11. In article <1992Aug12.141526.25165@athena.mit.edu>, chanh@athena.mit.edu
  12. (Chanh N. Vuong) writes:
  13. > In article <92225.09262732BFPQ3@CMUVM.CSV.CMICH.EDU> Nathan Owen
  14. <32BFPQ3@CMUVM.CSV.CMICH.EDU> writes:
  15. >>I having a problem writing a batch file.  I need a batch file which will go
  16. >>to a c:\Temp directory and delete every file in the directory except for
  17. >>a file named gest.bat.  The batch must be written in such a way they the
  18. >>user will not get a message asking Yes/No (Y/N) in response to deleting
  19. >>the files , which limits your use of wildcard deletes like del *.*.
  20. > DEL_TEMP.BAT:
  21. > @echo off
  22. > c:
  23. > cd \
  24. > cd temp
  25. > md tmp
  26. > copy gest.bat tmp
  27. > for %%a in (*.*) do del %%a
  28. > copy c:\temp\tmp\gest.bat .
  29. > del c:\temp\tmp\gest.bat
  30. > rd tmp
  31. > cd \
  32.  
  33. I'd add a bit of error checking to make sure the tmp dir is actually
  34. created.  e.g.
  35.  
  36. if not exist tmp\nul goto :md_failed
  37.  
  38. (With some versions of DOS you may have to put a colon after the device
  39. name - "nul:" - I'm getting a bit hazy on this.)
  40.  
  41. (NOTE:  The "if exist" test above won't work on at least some NetWare
  42. drives.  Regardless of how ficticious a directory name you give, you
  43. will be told that the file exists.  You also can't use this type of test
  44. on a NetWare drive to tell if you have read or filescan access to a dir
  45. - if you test for the existence of any of the DOS device psuedo files
  46. regardless of the directory structure and your access rights, "if exist"
  47. returns true.  I've never seen this "feature" mentioned anywhere before
  48. - surely I'm not the first to discover it!)
  49.  
  50. Also check that gest.bat copied OK before deleting all the files in the
  51. \temp dir and again before deleting the version in tmp.  There are other
  52. checks you could make as well - depends on how bomb-proof you want to
  53. make it and on who will be using it.
  54.  
  55. Nathan's claim that you won't be able to use "del *.*" is incorrect. 
  56. Try the following instead of Chanh Vuong's elegant "for..." line:
  57.  
  58. echo y >y.dat
  59. del *.* <y.dat >nul
  60.  
  61. From some experience I'd expect the above to execute faster if more than
  62. 3 or 4 files are being deleted.
  63.  
  64. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  65.  Nick FitzGerald, PC Applications Consultant, CSC, Uni of Canterbury, N.Z.
  66.  n.fitzgerald@csc.canterbury.ac.nz    (64)(3)  642-337 Voice,  642-332 FAX
  67.