Jump to content

[SOLVED] file_exists: but filenames have spaces


geekpie

Recommended Posts

Hi

This is all CLI php loop in XP.

 

is there a way round this problem (note space in filename before '[' ):

 

$newfile = '"'.$path_info['filename'] . ' [Compatibility Mode].pdf"';

while (!file_exists($newfile)){

echo "Waiting for file to exist " . $newfile;

}

 

The file never exists (and it does, after it's created by PDFCreator).

 

But if I subsitute the value in $newfile, it works, ie

 

while (!file_exists("abc [Compatibility Mode].pdf")){

 

exits the loop once abc [Compatibility Mode].pdf  is created

 

 

But it needs the quotes because the filename has a space.  Take the quotes away and you get a parse error.

 

Have you tried this theory?

 

$newfile = $path_info['filename'] . ' [Compatibility Mode].pdf';

 

 

The above line, compared to:

while (!file_exists("abc [Compatibility Mode].pdf")){

Is the exact same, except that the abc etc is stored in a variable.

 

Now take the original line:

$newfile = '"'.$path_info['filename'] . ' [Compatibility Mode].pdf"';

 

That is not the same, as $newfile will contain "abc [compatibility Mode].pdf" isntead of just abc [compatibility mode].pdf

 

Try it out and see, as I think you were too quick to shoot it down. Given the statement that the manually putting the name in the while loop works, the line change that I provided should work as well.

Thanks:  you were right to make me persist. 

 

I had become distracted into thinking I needed quotes around a filename containing a space because I did in this case in the same program:

 

$file = '"'.$file.'"';

$output = exec('ren '.$file .' '. $newname);

 

but that is different:  I am building a dos statement.  However that was enough to distract me as to how php worked.

 

Thanks again.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.