Gossamer Forum
Home : General : Perl Programming :

File Creation

Quote Reply
File Creation
How can you create a file when the name of the file you want to create, contains forward slashes - for example, file/name. If you attempt to create the file in the normal way (using OPEN..CLOSE), you get an error as the server tries to create a file named 'name' in a (non-existent) subdirectory called 'file' in the directory you are trying to create the file 'file/name'. The forward slash needs to be preserved in the filename. Ideas?

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln
Quote Reply
Re: [dan] File Creation In reply to
I don't think you can, AFAIK - could I ask what you are trying to achieve?

I tried a couple of ways before posting but neither worked....

Code:
my $var = qq!\x2!;
open F, ">./foo${var}bar" or die $!;
close F;


Code:
open F, ">./foo/bar" or die $!;
close F;
Quote Reply
Re: [Coombes] File Creation In reply to
I did try the second one earlier, but of course it failed. The script creates a file named after the user's authenticated username. Normally this would not be a problem. However, one [expletive deleted] billing company (ccBill) provides the option for some of their clients (that opt in) to have randomly usernames generated for new users. Problem is that they allow all word AND virtually all non-word characters (including $ and /). Out of curiosity, via FTP, I tried to rename an existing file to another filename that included the forward slash. No go - but also no surprise there. I think the only solution is to contact ccBill, and get them to revise their random username generator so that certain characters like forward slashes are not used in the username creation process.

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln
Quote Reply
Re: [dan] File Creation In reply to
Whoops my first example should be \x2F not \x2 - either way it still doesn't work :(

I think your idea of contacting CCBill may be the way to go.
Quote Reply
Re: [Coombes] File Creation In reply to
Well, I got a reply back from ccBill:

To turn off the special characters you will go to "Tools/Account Maintenance/Account Admin" and in the User Management you can set the "Special Characters" to yes or no. If you have any further questions please let us know.


Good enough I guess. I'll just instruct my clients do this. It was an unexpected surprise to get such a speedy response =) Almost as good as me. Thanks for your valued feedback!

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln
Quote Reply
Re: [dan] File Creation In reply to
Just done a bit of searching and with windows at least the following are not allowed in file names:

< > : " / \ |