Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!sdd.hp.com!mips!atha!aunro!alberta!mts.ucs.UAlberta.CA!Al_Dunbar From: userAKDU@mts.ucs.UAlberta.CA (Al Dunbar) Newsgroups: comp.os.msdos.misc Subject: Re: Passing path as Batch parameter Message-ID: Date: 10 May 91 03:49:35 GMT References: <375@galileo.rtn.ca.boeing.com> <1991May5.210006.417@sc2a.unige.ch> Organization: MTS Univ of Alberta Lines: 40 In article , I wrote: >In article <1991May5.210006.417@sc2a.unige.ch>, fisher@sc2a.unige.ch writes: >>In article <375@galileo.rtn.ca.boeing.com>, rfh3273@galileo.rtn.ca.boeing.com >>(Dick Harrigill) writes: >>> I have a generic problem with writing batch files. > ><<>> > >> >> SOLUTION: >> Use a little known trick to check the existence of a directory and >> a bit of fall-through logic. >> > ><<< deletions: explanation that NUL exists in all directories>>> ><<< code fragment follows: >>> >> >> set _vd= >> if exist %1NUL if exist %1\NUL set _vd=%1 >> if no%_vd% == no if exist %1\NUL set _vd=%1\ >> if no%_vd% == no if exist %1.\NUL set _vd=%1 >> if no%_vd% == no goto no_vd > >A neat trick, but not foolproof. It handles even the <<>> Here is another way it fails: If you pass the name "BILLY" where no such directory exists, but a file called BILLY.NUL does exist, the above code would declare "BILLY" as a valid directory. The solution to this glitch is to look for NUL.XXX (which has the same properties of existence as NUL), because BILLY.NUL.XXX can't exist to throw the code off the track. Note also, that other device names (CON, PRN) seem to work in place of NUL, but using NUL makes more sense. -------------------+------------------------------------------- Al Dunbar | Edmonton, Alberta | Disclaimer: "I disclaim disclaimers" CANADA | -------------------+-------------------------------------------