home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-387-Vol-3of3.iso
/
m
/
msh_ut11.zip
/
MYMKDIR.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1992-04-30
|
2KB
|
67 lines
PROGRAM MyMkdir;
{ Create a directory, and all non-existent father-direc-
tories as well. Not much of error-checking, so cross
your fingers...
J.P. 92 for the Mi-Shell }
uses dos;
{$i-}
PROCEDURE nope;
begin
writeLn('Could not create directory');
halt;
end;
PROCEDURE MkIt(dir : string);
var i, j : byte;
exist : boolean;
srec : SearchRec;
subdir: string;
begin
subdir := dir;
{ Which part of dir is already existing ? }
REPEAT
If subdir[Length(subdir)]='\' then
DEC(subdir[0]); { kill it }
FindFirst(subdir, AnyFile, srec);
exist := doserror = 0;
if exist then
begin
if srec.attr and directory = 0 then
begin
nope; { Oops, there is a normal file with that name }
end;
end
else
begin
j := Length(subdir);
WHILE (j>0) and (subdir[j]<>'\') AND (subdir[j]<>':') DO
DEC(j);
subdir[0] := chr(j);
if subdir[j] = ':' then
exist := true; { Only Drive-spec remaining }
end;
UNTIL exist OR (subdir='');
{ So what remains in subdir is the existing directory }
{ from this on we have to create all sub-directories }
subdir := subdir + '\';
i := Length(subdir); { From this we start on }
REPEAT
if dir[i]='\' then inc(i);
while (i<Length(dir)) and (dir[i]<>'\') do
inc(i);
subdir := Copy(dir, 1, i);
if subdir[length(subdir)] = '\' then
dec(subdir[0]);
mkdir(subdir);
if ioresult<>0 then nope;
UNTIL i>=Length(Dir);
end;
BEGIN
IF ParamCount>0 THEN
MkIt(ParamStr(1));
END.