tags:

views:

124

answers:

3

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

A: 

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.

Chris Thornton
I tried underscore no change Only if I remove ALL space the it works it does not make sense
Philippe Watel
As Tom said, you need to make sure you've got double-quotes around the whole thing. You're doing that, right?
Chris Thornton
+1  A: 

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?

Tom
The API neither wants nor accepts quotation marks in file names.
Rob Kennedy
I tried that Nope!Thanks for your help
Philippe Watel
+1  A: 

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;
François