Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-01

EFCreateError' Unable to create file

7 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

vmars

(Lazarus-0.9.26-fpc-2.2.2-win32.exe) winXP sp2
I am trying to SaveToFile a Memo1 to disk.
But can't seem to get it to work.
Is there a known bug?

            Try
            Memo1.Lines.SaveToFile(ExecuteName);
            Except ShowMessage('Shoots, couldnt SaveToFile!');
            end;

[Project raised exception class 'EFCreateError' with message: Unable to create file
""C:lazarusfpc2.2.2bini386-win32Del2PasDel2PasDel2Pas.bat""]

I'm wondering 'How come ExecuteName got all the \s taken out?'. 'F7' shows that :
'ExecuteName' =
"C:\lazarus\fpc\2.2.2\bin\i386-win32\Del2Pas\Del2Pas\Del2Pas.bat"

ô¿ô
V e r n

WinXp sp2 , Delphi5, WebDwarf, Trellian WebPage,
Lazarus-0.9.26-fpc-2.2.2-win32.exe,
wxPython2.8-win32-unicode-2.8.9.1-py26.exe , Boa 0.6.1 http://www.flickr.com/photos/vmars956/

Wanted: Dwarf Hibiscus (Orange/Rasberry)

Michael Van Canneyt
to vmars
vmars wrote 13 lines
(Lazarus-0.9.26-fpc-2.2.2-win32.exe) winXP sp2 I am trying to SaveToFile a Memo1 to disk. But can't seem to get it to work. Is there a known bug? Try Memo1.Lines.SaveToFile(ExecuteName); Except ShowMessage('Shoots, couldnt SaveToFile!'); end; [Project raised exception class 'EFCreateError' with message: Unable to create file ""C:lazarusfpc2.2.2bini386-win32Del2PasDel2PasDel2Pas.bat""]

I don't know why the backslashes are gone, but the fact that it shows double quotes twice is definitely weird. I don't think windows allows to use filenames with double quotes in it.

Michael.

Bart
to Michael Van Canneyt
Show quoted text 9 lines
> Try > Memo1.Lines.SaveToFile(ExecuteName); > Except ShowMessage('Shoots, couldnt SaveToFile!'); > end; > > [Project raised exception class 'EFCreateError' with message: > Unable to create file > ""C:lazarusfpc2.2.2bini386-win32Del2PasDel2PasDel2Pas.bat""]

You cannot create filenames that have double quotes (") in them on Windows (your ExecuteName has double quotes in it as you stated yourself), so the EFCreateError is correct.

See for yourself:

...
  Try
    Memo1.SaveToFile(ExecuteName);
  Except
    On E: Exception do
    begin
      ShowMessage('Exception occurred of '+E.ClassName+LineEnding+
        'Attempted to save to:'+LineEnding+>'+ExecuteName+'<');
    end;

And you will see:

Exception occurred of EFCreateError
Attempted to save to:

"C:\lazarus\fpc\2.2.2\bin\i386-win32\Del2Pas\Del2Pas\Del2Pas.bat"<

And you will see the double quotes in the filename...

I tested your code in Lazarus and in Delphi and both raise the error with the filename you supplied to SaveTofile (that is with all backslashes intact), so I cannot reproduce the second part of your "bug".

Bart

Vincent Snijders
to vmars: (Lazarus-0.9.26-fpc-2.2.2-win32.exe) winXP sp2 I am trying to SaveToFile a Memo1 to disk.…
vmars wrote 13 lines
(Lazarus-0.9.26-fpc-2.2.2-win32.exe) winXP sp2 I am trying to SaveToFile a Memo1 to disk. But can't seem to get it to work. Is there a known bug? Try Memo1.Lines.SaveToFile(ExecuteName); Except ShowMessage('Shoots, couldnt SaveToFile!'); end; [Project raised exception class 'EFCreateError' with message: Unable to create file ""C:lazarusfpc2.2.2bini386-win32Del2PasDel2PasDel2Pas.bat""]

It is imperfect handling of string that Lazarus gets from the debugger.

Vincent

vmars
to Bart: You cannot create filenames that have double quotes (") in them on Windows (your…

Double quotes are ok in windows.
Check your system for any ShortCut aimed at "c:\Program Files". And you'll see double quotes.

But your right about me having too many ""s.
I fixed that, and all is well.
Thanks All !

ô¿ô
V e r n

WinXp sp2 , Delphi5, WebDwarf, Trellian WebPage,
Lazarus-0.9.26-fpc-2.2.2-win32.exe,
wxPython2.8-win32-unicode-2.8.9.1-py26.exe , Boa 0.6.1 http://www.flickr.com/photos/vmars956/

Wanted: Dwarf Hibiscus (Orange/Rasberry)

Earlier message 52 lines
----- Original Message ----- From: "Bart" To: "FPC-Pascal users discussions" Sent: Sunday, January 25, 2009 5:36 AM Subject: Re: [fpc-pascal] EFCreateError' Unable to create file >> > Try >> > Memo1.Lines.SaveToFile(ExecuteName); >> > Except ShowMessage('Shoots, couldnt SaveToFile!'); >> > end; >> > >> > [Project raised exception class 'EFCreateError' with message: >> > Unable to create file >> > ""C:lazarusfpc2.2.2bini386-win32Del2PasDel2PasDel2Pas.bat""] >> > > You cannot create filenames that have double quotes (") in them on > Windows (your ExecuteName has double quotes in it as you stated > yourself), so the EFCreateError is correct. > > See for yourself: > > ... > Try > Memo1.SaveToFile(ExecuteName); > Except > On E: Exception do > begin > ShowMessage('Exception occurred of '+E.ClassName+LineEnding+ > 'Attempted to save to:'+LineEnding+>'+ExecuteName+'<'); > end; > > And you will see: > > Exception occurred of EFCreateError > Attempted to save to: >>"C:\lazarus\fpc\2.2.2\bin\i386-win32\Del2Pas\Del2Pas\Del2Pas.bat"< > > And you will see the double quotes in the filename... > > > I tested your code in Lazarus and in Delphi and both raise the error > with the filename you supplied to SaveTofile (that is with all > backslashes intact), so I cannot reproduce the second part of your > "bug". > > Bart > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal >
Bart
to vmars
vmars wrote
Double quotes are ok in windows. Check your system for any ShortCut aimed at "c:\Program Files". And you'll see double quotes.

I know, but that is not what I meant by saying that double quotes are not allowed in the filename. By that I meant they are not allowed as part of the filename itself.
The double quotes around the filename are put there and interpreted by the shell (OS).

If you ask the OS directly for the filename, there will be no double quotes in it.
Check for yourself

In a DOS box do
C:>copy con "1 2 3.txt"
test file with spaces in its name
^Z (that is press Ctrl+Z) and press Enter.

Now you create a file with spaces in its name.
The shell (cmd.exe in W2K or higher) handles the double quotes. (It actually needs these to know if a space is part of the filename, or it means that the next part of the command is a new parameter)

Now write a program and with FindFirst retrieve the filname and see: the double quotes are not there.

Bart

vmars
to Bart

Ahh.., I see.
Thanks!

ô¿ô
V e r n

WinXp sp2 , Delphi5, WebDwarf, Trellian WebPage,
Lazarus-0.9.26-fpc-2.2.2-win32.exe,
wxPython2.8-win32-unicode-2.8.9.1-py26.exe , Boa 0.6.1 http://www.flickr.com/photos/vmars956/

Wanted: Dwarf Hibiscus (Orange/Rasberry)

Earlier message 40 lines
----- Original Message ----- From: "Bart" To: "FPC-Pascal users discussions" Sent: Monday, January 26, 2009 12:58 PM Subject: Re: [fpc-pascal] EFCreateError' Unable to create file > On 1/26/09, vmars wrote: >> Double quotes are ok in windows. >> Check your system for any ShortCut aimed at "c:\Program Files". >> And you'll see double quotes. > > I know, but that is not what I meant by saying that double quotes are > not allowed in the filename. By that I meant they are not allowed as > part of the filename itself. > The double quotes around the filename are put there and interpreted by > the shell (OS). > > If you ask the OS directly for the filename, there will be no double > quotes in it. > Check for yourself > > In a DOS box do > C:>copy con "1 2 3.txt" > test file with spaces in its name > ^Z (that is press Ctrl+Z) and press Enter. > > Now you create a file with spaces in its name. > The shell (cmd.exe in W2K or higher) handles the double quotes. > (It actually needs these to know if a space is part of the filename, > or it means that the next part of the command is a new parameter) > > Now write a program and with FindFirst retrieve the filname and see: > the double quotes are not there. > > Bart > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal >