简体   繁体   English

无法理解Delphi Windows文件名

[英]Cannot make sense out a Delphi windows file name

I am trying to copy from a file X to this name 我正在尝试从文件X复制到此名称

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. 由于命令行副本通常需要在文件名两边加上双引号,因此我想知道API是否需要类似的东西。 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: 我在Win7上尝试了D2010,并与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. 调用GetLastError来查找是否抛出错误。 Windows may be trying to tell you something, and your code isn't listening. Windows可能正在尝试告诉您一些信息,并且您的代码没有监听。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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