: Hello. I have a problem with reading from a file. The filename
: contains numbers and pascal doesn't allow it. It says that the file
: is not found. If I rename it to only letters, it works. How can I
: fix this? (e.x. filename: 070321650.txt)
What compiler and OS are you using ? TP7 supports all sorts of filenames but cannot open long names by default. For example
070321650.txt probably has a short dos name of
070321~1.txt, trying that will most likely fix your problem. You could also try the following unit to have long filename support:
{ Compiler BP/TP7 }
UNIT W95;
INTERFACE
{$A+,D-,G+,L-,O-,X+}
type
tSearchRec = record
Attr: longint;
Creation: comp;
LastAccess: comp;
LastModification: comp;
HighFileSize: longint;
LowFileSize: longint;
Reserved: comp;
Name: array[0..259] of char;
ShortName: array[0..13] of char;
Handle: word;
end;
const
faReadOnly = $01;
faHidden = $02;
faSysFile = $04;
faVolumeID = $08;
faDirectory = $10;
faArchive = $20;
faAnyFile = $3F;
FUNCTION Win95Loaded: boolean;
FUNCTION GetLongName(FName: string): string;
FUNCTION FindFirst(FileSpec: string; Attr: word; var S: tSearchRec): integer;
FUNCTION FindNext(var S: tSearchRec): integer;
FUNCTION FindClose(var S: tSearchRec): integer;
var WIN95SYSTEM: boolean;
IMPLEMENTATION
uses dos,strings;
{==========================================================================}
FUNCTION Win95Loaded: boolean;
{--------------------------------------------------------------------------}
var
Ver: word;
P: pChar;
{-------------------------------------------------------------}
function GetAnyCaseEnv(VarName: pChar): pChar;
var
L: word;
P: pChar;
begin
L := StrLen(VarName);
P := Ptr(Word(Ptr(PrefixSeg,$2C)^),0);
while P^ <> #0 do begin
if (StrLIComp(P,VarName,L) = 0) and (P[L] = '=') then begin
GetAnyCaseEnv := P + L + 1;
Exit;
end;
Inc(P,StrLen(P) + 1);
end;
GetAnyCaseEnv := Nil;
end;
{-------------------------------------------------------------}
function GetCurLongDir(Dir: pChar; Drive: byte): pChar; assembler;
asm
mov al,Drive
or al,al
jne @@1
mov ah,19h
int 21H
inc ax
@@1: mov dl,al
push ds
lds si,Dir
push ds
push si
mov byte ptr es:[si],0
mov ax,7147h { note AH=$71, AL=$47, not AH=$47 as in standard DOS }
int 21h
pop ax
pop dx
pop ds
end;
{-------------------------------------------------------------}
begin
Win95Loaded := False;
Ver := DosVersion;
if (Lo(Ver) = 7) and (Hi(Ver) = 0) then begin
if GetAnyCaseEnv('winbootdir') <> Nil then begin
GetMem(P,256);
if StrLen(GetCurLongDir(P,0)) > 0 then Win95Loaded := True;
FreeMem(P,256);
end;
end;
end; { Win95Loaded }
{==========================================================================}
FUNCTION FindFirst(FileSpec: string; Attr: word; var S: tSearchRec): integer;
{--------------------------------------------------------------------------}
begin
FileSpec := FileSpec + #0;
S.Attr := Attr;
asm
push ds
push ss
pop ds
lea dx,filespec+1
les di,S
mov ax,$714e
mov cx,attr
mov si,0
int $21
les di,S
mov word ptr es:[di+TSearchRec.handle], ax
jc @1
xor ax,ax
@1:
mov @result,ax
pop ds
end;
end;
{==========================================================================}
FUNCTION FindNext(var S: tSearchRec): integer;
{--------------------------------------------------------------------------}
begin
asm
mov ax,$714f
mov si,0
les di,S
mov bx,word ptr es:[di+tSearchRec.Handle]
int $21
jc @1
xor ax,ax
@1:
mov @result,ax
end;
end;
{==========================================================================}
FUNCTION FindClose(var S: tSearchRec): integer;
{--------------------------------------------------------------------------}
begin
asm
mov ax,$71a1
les di,S
mov bx,word ptr es:[di+tSearchRec.Handle]
int $21
jc @1
xor ax,ax
@1:
mov @result,ax
end;
end;
{==========================================================================}
FUNCTION GetLongName(FName: string): string;
{--------------------------------------------------------------------------}
var
SR: tSearchRec;
Res: Integer;
begin
GetLongName := '';
Res := FindFirst(FName,faAnyFile-faVolumeID,SR);
if (Res = 0) and (SR.ShortName[0] <> #0) then begin
if (SR.Name[0] <> #0) then GetLongName := StrPas(SR.Name);
end;
FindClose(SR);
end;
BEGIN
if Win95Loaded then WIN95SYSTEM := True else WIN95SYSTEM := False;
END.