Philippe Watel
Philippe Watel

Reputation: 43

Cannot make sense out a Delphi windows file name

I am trying to copy from a file X to this name

C:\RIP2\France Clidat\Les Plus Belles Oeuvres - France Clidat\(01)3_ Un Sospiro.flac

I have checked that there is no bad characters, If I force directorires it creates

C:\RIP2\France Clidat\Les Plus Belles Oeuvres - France Clidat

but it refuses to write the file and I do not understand why a simple test

procedure foo(str: string);
var
  f:File;
begin
  Assign(f,str);
  Rewrite(f);
  CloseFile(f);
end;

will crash saying it is not a valid file name but it is! If I remove ALL blank spaces it works
I am lost please Help

Upvotes: 0

Views: 341

Answers (3)

Francesca
Francesca

Reputation: 21650

Try to make sure your directories are there before you try to create the file in them.
I tried with D2010 on Win7 and it worked with ForceDirectories:

const
  sFilename = 'C:\RIP2\France Clidat\Les Plus Belles Oeuvres - France Clidat\(01)3_ Un Sospiro.flac';

procedure foo(str: string);
var
  f: File;
begin
  if not ForceDirectories(ExtractFileDir(str)) then
    showMessage('ForceDirectories failed')
  else
  begin
    AssignFile(f,str);
    Rewrite(f);
    CloseFile(f);
  end;
end;

procedure TForm10.Button1Click(Sender: TObject);
begin
  foo(sFilename);
end;

Upvotes: 1

Tom A
Tom A

Reputation: 1682

Since command line copies usually require wrapping double quotes around the file name, I'm wondering if the API would need something similar. Maybe try single or double quotes to see if that solves the problem?

Upvotes: 1

Chris Thornton
Chris Thornton

Reputation: 15817

Try some tests to see if it's objecting to the parens, underscore, spaces, etc.. Then you'll know more.
Call GetLastError to find out if you're throwing an error. Windows may be trying to tell you something, and your code isn't listening.

Upvotes: 0

Related Questions