note 56231 added to function.glob

From: Date: Sun, 28 Aug 2005 07:59:32 +0000
Subject: note 56231 added to function.glob
Groups: php.notes 
Request: Send a blank email to php-notes+get-94283@lists.php.net to get a copy of this message
Whilst on Windows, a path starting with a slash resolves OK for most file functions - but NOT glob. If the server is LAUNCHED (or chdir()ed) to W:, then file_exists("/temp/test.txt") returns true for the file "W:/temp/test.txt". But glob("/temp/*.txt") FAILS to find it! A solution (if you want to avoid getting drive letters into your code) is to chdir() first, then just look for the file. <?php $glob="/temp/*.txt"; chdir(dirname($glob)); // getcwd() is now actually "W:\temp" or whatever foreach (glob(basename($glob)) as $filename) { $filepath = dirname($glob)."/".$filename; // must re-attach full path echo "$filepath size " . filesize($filepath) . "\n"; } ?> Note also, glob() IS case sensitive although most other file funcs on Windows are not. ---- Manual Page -- http://www.php.net/manual/en/function.glob.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+56231 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56231&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56231&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56231&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56231&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56231&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56231&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+56231&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#94283) next »