<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Read from a file.' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Read from a file.' posted on the 'Pascal' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2010 Programmers Heaven</copyright>
    <pubDate>Thu, 18 Mar 2010 04:47:06 -0700</pubDate>
    <lastBuildDate>Thu, 18 Mar 2010 04:47:06 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Read from a file.</title>
      <link>http://www.programmersheaven.com/mb/pasprog/409691/409691/read-from-a-file/</link>
      <description>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)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/409691/409691/read-from-a-file/</guid>
      <pubDate>Sat, 21 Nov 2009 09:26:47 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: Read from a file.</title>
      <link>http://www.programmersheaven.com/mb/pasprog/409691/409699/re-read-from-a-file/#409699</link>
      <description>: Hello. I have a problem with reading from a file. The filename &lt;br /&gt;
: contains numbers and pascal doesn't allow it. It says that the file &lt;br /&gt;
: is not found. If I rename it to only letters, it works. How can I &lt;br /&gt;
: fix this? (e.x. filename: 070321650.txt)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
What compiler and OS are you using ? TP7 supports all sorts of filenames but cannot open long names by default. For example &lt;strong&gt;070321650.txt&lt;/strong&gt; probably has a short dos name of &lt;strong&gt;070321~1.txt&lt;/strong&gt;, trying that will most likely fix your problem. You could also try the following unit to have long filename support:&lt;pre class="sourcecode"&gt;&lt;span style="color: Blue;"&gt;{ 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^ &amp;lt;&amp;gt; #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') &amp;lt;&amp;gt; Nil then begin
         GetMem(P,256);
         if StrLen(GetCurLongDir(P,0)) &amp;gt; 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] &amp;lt;&amp;gt; #0) then begin
      if (SR.Name[0] &amp;lt;&amp;gt; #0) then GetLongName := StrPas(SR.Name);
   end;
   FindClose(SR);
end;


BEGIN
   if Win95Loaded then WIN95SYSTEM := True else WIN95SYSTEM := False;
END.

&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/409691/409699/re-read-from-a-file/#409699</guid>
      <pubDate>Sat, 21 Nov 2009 15:45:51 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: Read from a file.</title>
      <link>http://www.programmersheaven.com/mb/pasprog/409691/409716/re-read-from-a-file/#409716</link>
      <description>I'm using WinXP and TP7. About the unit: How should i rename the extension? TPU? And should i change something in it so it works? Or just add it to the program like "uses longname;"?&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/409691/409716/re-read-from-a-file/#409716</guid>
      <pubDate>Sun, 22 Nov 2009 05:37:08 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: Read from a file.</title>
      <link>http://www.programmersheaven.com/mb/pasprog/409691/409747/re-read-from-a-file/#409747</link>
      <description>: I'm using WinXP and TP7. About the unit: How should i rename the &lt;br /&gt;
: extension? TPU? And should i change something in it so it works? Or &lt;br /&gt;
: just add it to the program like "uses longname;"?&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
Compile the unit first, set destination: disk, it should generate a TPU file, then add it to the program: "uses w95;"  First scan for text files to get the short names, use the getlongname function to find out the long name, see if it matches, then open it the usual way using the short name.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/409691/409747/re-read-from-a-file/#409747</guid>
      <pubDate>Sun, 22 Nov 2009 21:29:18 -0700</pubDate>
      <category>Pascal</category>
    </item>
  </channel>
</rss>