简体   繁体   中英

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

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?

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;

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM