Re: open() : Files that don't exist
- Posted by Ryan W. Johnson <ryanj at fluidae.com> Dec 31, 2005
- 456 views
don cole wrote: > > Alex Chamberlain wrote: > > > > Why does }}} <eucode>open("debug.txt", "w")</eucode> {{{ create a file called > > "DEBUG.TXT"? > > Is there a way to get around this? > > > > Thanks, > > Alex > > global function exist(sequence fileOrFolder) > object x > x=dir(fileOrFolder) > if atom(x) then > return 0 > else > return 1 > end if > end function > > if exist("debug.txt") then > open("debug.txt", "w") > else > --do nothing > end if > > Don Cole You can use open("debug.txt", "r") to see whether or not the file exists. It will return -1 if it doesn't exist. About the ALL CAPS filename, i believe that is because it is using the DOS file formate. The reference manual says: "DOS32: When running under Windows 95 or later, you can open any existing file that has a long file or directory name in its path (i.e. greater than the standard DOS 8.3 format) using any open mode - read, write etc. However, if you try to create a new file (open with "w" or "a" and the file does not already exist) then the name will be truncated if necessary to an 8.3 style name. We hope to support creation of new long-filename files in a future release." To create a file with a long filename, maybe you could try somehting like this:
fn = open("debug.txt", "w") close(fn) system("rename DEBUG.TXT debug.txt", 2) fn = open("debug.txt", "w")
Just an idea. I can't test this right now, because I switched to linux! ~Ryan W. Johnson Fluid Application Environment http://www.fluidae.com/ [cool quote here, if i ever think of one...]