Re: open files.

BeHealthy@xxxxxxxxx wrote:
> If I use open(fp, $FILENAME), where $FILENAME contains some
> subdirectory that hasn't been set up yet, then it fails.

open() is not used for directories, it is used for files.
perhaps you're thinking of 'opendir()'?

> Is there any
> way I can get around this by letting the program to create the
> subdirectory if needed?

Your algorithm needs some rethinking. You're opening a directory. If
you want to use an analogy to opening files, you're opening the
directory "for reading". There is no such thing as opening a directory
"for writing". If the directory doesn't exist, even if there were a
built-in way to make open auto-create the directory, it would be
created empty. You would then have nothing to read from it.

It's time for you to tell us what you're *actually* trying to
accomplish, rather than ask for help with the method you've already
decided to use to accomplish this unknown goal.

FWIW, I don't see any particular reason you can't just do:
-d $directory_name or mkdir $directory_name
or die "Couldn't create directory $directory_name: $!\n";

(with the possible exception of the chance of a race condition)

Paul Lalli


Relevant Pages

  • Re: how does aio_write() work
    ... or just opening the file once for evey new filename (*ie ... when the file doesnt exist), getting the file descriptor, and closing ...
  • Re: a good programming text editor (not IDE)
    ... the filename to lowercase. ... is case-insensitive but case-preserving, and PyPE uses Python's ... mistake of opening the same file twice. ... running on any non-OSX *nix (whose filename case handling is not like ...
  • Word having problem to open file
    ... The document 'Filename' caused a serious error the ... opening it? ... i tried knowledgebase article# 286017 and 817137. ... Mitesh ...
  • Re: Can a file be deleted even if it is in use.
    ... I have created an application in C which has some file handling ... The application starts with opening a file using ... rm -f,dammit,dammit <filename> which kills anything using the ...
  • RE: GetOpenFilename path vs filename
    ... I need to evaulate the directory and path 'before' opening ... the file because the importing of the data structure depends on where it is ... GetOpenFilename returns the path and filename together. ...