mridang_agarwal Posted June 13, 2007 Share Posted June 13, 2007 Could anyone tell me what characters are allowed in UNIX/ Windows file and directory names. Quote Link to comment https://forums.phpfreaks.com/topic/55441-charcters-in-unix-file-and-directory-names/ Share on other sites More sharing options...
trq Posted June 13, 2007 Share Posted June 13, 2007 Its safe to use any combination of letters / numbers _ - . and no spaces in *nix filenames. Anything alse is going to cause you problems. Quote Link to comment https://forums.phpfreaks.com/topic/55441-charcters-in-unix-file-and-directory-names/#findComment-274011 Share on other sites More sharing options...
mridang_agarwal Posted June 13, 2007 Author Share Posted June 13, 2007 i have string. how do i check if it only contains numbers, aplhabtes, . - and _ Quote Link to comment https://forums.phpfreaks.com/topic/55441-charcters-in-unix-file-and-directory-names/#findComment-274028 Share on other sites More sharing options...
neel_basu Posted June 13, 2007 Share Posted June 13, 2007 UNIX filenames or Directory name can contain anything other than a / Character. I dont have Windows I use Linux In windows Create a new file and then try renaminf it to a String that contains a / when you press that Windows will show you which characters are not Allowed Quote Link to comment https://forums.phpfreaks.com/topic/55441-charcters-in-unix-file-and-directory-names/#findComment-274033 Share on other sites More sharing options...
trq Posted June 13, 2007 Share Posted June 13, 2007 i have string. how do i check if it only contains numbers, aplhabtes, . - and _ Use preg_match. UNIX filenames or Directory name can contain anything other than a / Character. But I wouldn't recommend using anything other than what Ive suggested. Special chars can wreak havoc with shell expansion. Quote Link to comment https://forums.phpfreaks.com/topic/55441-charcters-in-unix-file-and-directory-names/#findComment-274254 Share on other sites More sharing options...
mridang_agarwal Posted June 14, 2007 Author Share Posted June 14, 2007 anyone know a good regex to validate a windows/UNIX path? no filenames . just the path Quote Link to comment https://forums.phpfreaks.com/topic/55441-charcters-in-unix-file-and-directory-names/#findComment-274597 Share on other sites More sharing options...
mridang_agarwal Posted June 15, 2007 Author Share Posted June 15, 2007 even a good regex to validate a URL would do Quote Link to comment https://forums.phpfreaks.com/topic/55441-charcters-in-unix-file-and-directory-names/#findComment-275231 Share on other sites More sharing options...
Wuhtzu Posted June 15, 2007 Share Posted June 15, 2007 I think you should take thorpe's advice and only allow letters, numbers, underscore, minus and dot. If that is the case a regex to test a filename would look like this: preg_match("/([a-z0-9\._-])+/i",$filename) And for the path: preg_match("/([a-z0-9\.\\\/_-])+/",$path) I'm not 100% sure if / (slash) is a special character and needs escaping by \ (backslash). So the "\\\/" part of the regex is first escaping a backslash "\\" and then escaping a slash "\/" but notice that I wasn't sure if / (slash) needed escaping. Furthermore I don't know if you want both / and \ to be allowed in the path... And if the two code pieces don't speak for them selves I would recommend you to split up the path in "path" and "filename" By the way this is a very useful regex site: http://www.regular-expressions.info/reference.html Quote Link to comment https://forums.phpfreaks.com/topic/55441-charcters-in-unix-file-and-directory-names/#findComment-275234 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.