'=========================================================================== ' Subject: SCAN DOS DIRECTORIES Date: 04-20-00 (21:22) ' Author: Hermann Seegert Code: PB ' Origin: hermann.seegert@t-online.de Packet: DOS.ABC '=========================================================================== $if 0 Detmold, Germany April 2000 ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿Ü ³ Hi everyone ! ³Û ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙÛ ßßßßßßßßßßßßßßßßßß I have to apologize for my- in parts- not very fine stuff, which I've sent to our William in february. If someone was downloading the SCANDIRS.BAS under DOS.ABC, he/she will probably have found some mistakes, especially in SUB masc(...). It was to late to send William the new version of SCANDIRS.BAS, and so I decided to send him this part of SCANDIRS.BAS without mistakes (or let's say: I hope, there are no mistakes in it now) as a kind of consolation. I'm realy sorry about that, but nobody is perfect, isn't it? I think, you can put this into SCANDIRS.BAS easily. The mistakes were in SUB masc(...). The rest is in here, because so you may find out, for what this also can be needed. Coments and remarks you can send to: hermann.seegert@t-online.de Programmed in PowerBASIC, Version 3.2 $endif '--------- Demo Code begin..... cls from_path$=command$ 'from_path$="c:\~aaa~\*.txt" if from_path$="" then ? "FROM PATH is ACTUAL PATH!" else ? "FROM PATH ";from_path$ end if call masc(from_path$,path$,mask$) ? "FROM PATH ";from_path$ ? "PATH ";path$ ? "MASK ";mask$ '--------- Demo Code end..... end ' '---------------------- file mask and path ------------------------- ' sub masc(from_path$,path$,mask$) 'here procedure SUB right_in_string(signs$,back1$,back2$) is nee- 'ded; also the SUB checkpath(path$) ' 'Well, we all want to have a little bit of comfort like the input 'under dos. Instead of typing *.txt we want to type .txt. With the ' following, all this is possible. ' on local error resume next actpath$=curdir$ if from_path$="" then 'nothing? Then it's the current from_path$=rtrim$(actpath$,"\")+"\*.*" 'directory, so we ca add *.* elseif from_path$="\" then 'Root of CURRENT drive, from_path$=left$(actpath$,3)+"*.*" 'so we can add *.* elseif right$(from_path$,1)=":" and _ 'Root of ANY drive, len(from_path$)=2 then 'so we can add *.* from_path$=from_path$+"\*.*" elseif from_path$=".." then 'like under dos.... from_path$=actpath$ call right_in_string(from_path$,from_path$,"") from_path$=from_path$+"\*.*" 'here it is: the previous dir.! elseif left$(from_path$,1)<>"\" and _ 'it's the next dir. or a mask mid$(from_path$,2,2)<>":\" then from_path$=rtrim$(actpath$,"\")+"\"+from_path$ elseif left$(from_path$,1)="\" then 'it's going over root- dir. from_path$=left$(actpath$,2)+from_path$ end if 'Until now, we don't know, if 'from_path$' is only a path or a path 'with a file or a mask. But we will find out soon, so wait......... call right_in_string(from_path$,x1$,x2$) 'you were typing in e.g.: c:\dos\.txt (changing into: ...\*.txt) if left$(x2$,1)="." then x2$="*."+mid$(x2$,2) 'you were typing in e.g.: c:\dos\letters. (changing into: ...\letters.*) if right$(x2$,1)="." then x2$=left$(x2$,len(x2$)-1)+".*" from_path$=x1$+"\"+x2$ 'build the whole string ' z?=attrib(from_path$) 'if here will occur an error, this 'doesn't matter. If you have joker 'and wildcards in from_path$, normal- 'ly here will be an error then. This 'is the main reason for a local er- 'ror- handler in this procedure, and 'because of this construction it's 'working (try it out with several in- 'puts!). if bit(z?,4) then 'then it's a directory, from_path$=rtrim$(from_path$,"\")+"\*.*" 'so we can add *.* as a mask end if 'in nearly each case, now we have the filemask and the directory... 'let's have a look again for path and mask for our final work! call right_in_string(from_path$,path$,mask$) 'The following isn't REALY necessary, but in each case we want to 'have path and mask; e.g. we need them both for good screen- messa- 'ges. The one case, we don't have a mask is the one, we have made 'an input with the root of a physical drive bit(...,4) doesn't 'recognize this as a directory. But this is no problem, because 'now we have the informations. And if not- as in this case, we can 'write *.* instead! if mask$="" then mask$="*.*" 'because we want to know, if the given path is valid, we call the 'procedure sub checkpath(...) to find out! if right$(path$,1)=":" then path$=path$+"\" 'root- directories.... call checkpath(path$) end sub ' '------------------ check out, if path is valid -------------------- ' sub checkpath(path$) on local error resume next actpath2$=curdir$ chdrive left$(path$,1) chdir mid$(path$,3) if err<>0 then if err=71 or err=72 then ? tab(5) "Invalid drive, make a correct input......" else ? tab(5) "Invalid path, make a correct input......." end if chdrive left$(actpath2$,1) chdir mid$(actpath2$,3) end 'program ends because of invalid path end if chdrive left$(actpath2$,1) 'back to where we come from ;) chdir mid$(actpath2$,3) 'back to where we come from ;) end sub ' '--------------- a simple INSTR from right ------------------------- ' sub right_in_string(signs$,back1$,back2$) 'for sub masc(...), back1$=left to delimiter, back2$=mid$ delimiter ' to the end for a=len(signs$) to 1 step -1 if mid$(signs$,a,1)="\" then decr a : exit next a back1$=left$(signs$,a) 'here: path back2$=mid$(signs$,a+2) 'here: file mask end sub ' '******************************* EOF *******************************