删除文件名称上带有空格的文件

时间:2021-01-06 11:14:54

I have a file named "my file.pdf" and I can't delete this file with this code:

我有一个名为“my file.pdf”的文件,我无法使用以下代码删除此文件:

if (remove("/var/tmp/\"my file.pdf\"") != 0)
            printf( "Error deleting file\n");

Any suggestion different than do some regex to replace '{whitespace}' for '\{whitespace}'?

有什么建议不同于做一些正则表达式来替换'\ {whitespace}'的'{whitespace}'吗?

2 个解决方案

#1


The remove() function does not use regexes. Does your file really contain quote characters as well as spaces? If not, and if the file contains a single space then:

remove()函数不使用正则表达式。你的文件真的包含引号字符和空格吗?如果没有,如果文件包含单个空格,则:

if (remove("/var/tmp/my file.pdf") != 0)

should work.

#2


How about

if (remove("\"/var/tmp/my file.pdf\"") != 0)
    printf( "Error deleting file");

?

#1


The remove() function does not use regexes. Does your file really contain quote characters as well as spaces? If not, and if the file contains a single space then:

remove()函数不使用正则表达式。你的文件真的包含引号字符和空格吗?如果没有,如果文件包含单个空格,则:

if (remove("/var/tmp/my file.pdf") != 0)

should work.

#2


How about

if (remove("\"/var/tmp/my file.pdf\"") != 0)
    printf( "Error deleting file");

?