function for safe filenames?
Hi,
Just wondering if there is a function to create safe filenames? If i use peoples nicks to create a file they often have "|" or "\" or "/", I have seen somewhere a function for "safe sql-queries" but is there one for filenames? I have made my own but I don't think it is... well it's probably not that efficient, and I don't know how to check some characters :S If someone could point me to an "safe filename" function or help me with this one I would be greatefull! Code:
I know some of the characters ARE valid in filenames but I don't want them in my filenames thats why they are in the function. |
Re: function for safe filenames?
You can try doing the carrot in single quotes. Single quotes stand for a single character. You'll probably have to do something other than the "replace_all" function to do it, though. I don't really know.
|
Re: function for safe filenames?
Quote:
Code:
Code:
Quote:
|
Re: function for safe filenames?
Thank you!
There is no more efficent way to do what i'm trying to do it? Well nevermind, this works and if there isn't a verry good way of doing it I'll stick to this. Thanks again! |
Re: function for safe filenames?
Code:
|
Re: function for safe filenames?
Hi, again.
Don't know if I have stumbled onto a bug? :s The replace_all works... sort of. When I try to replace | <'more' in unix i believe the character is> it works ok. When I try double || after eachother it works. But the other day I was recording a guy with the nick "Ban |Vle p|Z !" = " Ban Me plZ ! " then it refused to record the demo. I figured out that if i used the nick "| | !" it would not record but if i used "| |" it recorded. Well, when i say it didn't record I really mean it didn't create the file. So... I'm lost here, why didn't replace_all work? According to my code above with the corrections from Black Rose. I'll try jim_yang's way to see if that solves it. |
Re: function for safe filenames?
"| | !" doesn't work
"| |" works What's the difference? The exclamation mark. So replace your exclamation mark with an underscore as well. I'd just make a function like this, if it's for demos. It converts anything that isn't a letter or number to an underscore. Code:
|
Re: function for safe filenames?
Wow, that's quick!
That's perfect, thank you! |
Re: function for safe filenames?
I don't know what isalnum returns on the null character (string terminator), so to be sure, you might want to change "i<len" to "i<len-1", for safety.
|
Re: function for safe filenames?
i<len won't reach the \0
|
| All times are GMT -4. The time now is 04:54. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.