note 51228 added to function.glob

From: Date: Wed, 23 Mar 2005 23:23:59 +0000
Subject: note 51228 added to function.glob
Groups: php.notes 
Request: Send a blank email to php-notes+get-86866@lists.php.net to get a copy of this message
glob caused me some real pain in the buttom on windows, because of the DOS thing with paths (backslashes instead of slashes)... This was my own fault because I "forgot" that the backslash, when used in strings, needs to be escaped, but well, it can cause a lot of confusion, even for people who are not exactly newbies anymore... For some reason, I didn't have this problem with other file operations (chdir, opendir, etc...), which was the most confusing of all... So, for people running scripts on Windows machines (Dos95, 98 or WinNT or DosXP), just remember this: glob('c:\temp\*.*'); // works correctly, returns an array with files. glob("c:\temp\*.*"); // does NOT work... the backslashes need to be escaped... glob("c:\\temp\\*.*"); // that works again... This is especially confusing when temporary writable directories are returned as an unescaped string. $tempdir = getenv('TEMP'); // this returns "C:\DOCUME~1\user\LOCALS~1\Temp" so in order to scan that directoy I need to do: glob($tempdir . "\\*.*"); Or perhaps it's easier to replace all backslashes with slashes in order to avoid these kinds of confusions... glob("c:/temp/*.*"); // works fine too... I know I'm not contributing anything new here, but I just hope this post may avoid some unnecessary headaches... ---- Manual Page -- http://www.php.net/manual/en/function.glob.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51228 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51228&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51228&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51228&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51228&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51228&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51228&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#86866) next »