[Win32utils-devel] File.nopen alpha
win32utils-devel at rubyforge.org
win32utils-devel at rubyforge.org
Thu Nov 11 13:04:30 EST 2004
Hi all,
I've committed an alpha version of File.nopen (native open) to
win32-file. This is a wrapper for CreateFile(). A quick synopsis:
* File.nopen(file,access_mode,share_mode,creation_mode,flags)
*
* A 'native' open method. This uses CreateFile() behind the scenes
instead of
* the _open() function. This allows much greater flexibility when it
comes
* to Windows files. It also allows you to open directories, which
File.open
* cannot do on Windows.
*
* The access mode defaults to READ_DATA | WRITE_DATA
* The share mode defaults to SHARE_READ | SHARE_WRITE
* The creation mode defaults to OPEN_EXISTING
* The flags default to NORMAL
*
* To open a directory, pass File::BACKUP_SEMANTICS as the 'flags'
argument.
So, with this I can do:
dir = "C:\\TEST" # directory
fh = File.nopen(dir,nil,nil,nil,File::BACKUP_SEMANTICS)
p fh # Yup, it's a File object
p fh.class # File
fh.close
I can also open a plain file and read the contents. So far, so good.
But, when I try to write to the file, I get an IOError claiming the file
isn't opened for writing. Shouldn't the WRITE_DATA flag have given me
permission to write? I tried combinations of some other flags with no
luck.
Also, I noticed that if I try to use some of the new instance methods
like this:
fh = File.nopen("C:\\temp.txt",File::WRITE_ATTRIBUTES)
fh.hidden = true
fh.close
I get "test.rb:16:in `hidden=': cannot convert nil into String
(TypeError)"
Any ideas on these?
Please take a look and also let me know what you think in general of an
nopen() method.
Regards,
Dan
More information about the win32utils-devel
mailing list