note 51228 deleted from function.glob by cmb

From: Date: Sun, 28 Jul 2019 08:10:48 +0000
Subject: note 51228 deleted from function.glob by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-211725@lists.php.net to get a copy of this message
Note Submitter: fraggy(AT)chello.nl ---- 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...

« previous php.notes (#211725) next »