Class | File |
In: |
lib/win32/file.rb
|
Parent: | Object |
VERSION | = | '0.5.4' | ||
MAX_PATH | = | 260 | ||
ARCHIVE | = | FILE_ATTRIBUTE_ARCHIVE | Abbreviated attribute constants for convenience | |
COMPRESSED | = | FILE_ATTRIBUTE_COMPRESSED | ||
HIDDEN | = | FILE_ATTRIBUTE_HIDDEN | ||
NORMAL | = | FILE_ATTRIBUTE_NORMAL | ||
OFFLINE | = | FILE_ATTRIBUTE_OFFLINE | ||
READONLY | = | FILE_ATTRIBUTE_READONLY | ||
SYSTEM | = | FILE_ATTRIBUTE_SYSTEM | ||
TEMPORARY | = | FILE_ATTRIBUTE_TEMPORARY | ||
INDEXED | = | 0x0002000 | ||
CONTENT_INDEXED | = | 0x0002000 | ||
FULL | = | STANDARD_RIGHTS_ALL | FILE_READ_DATA | FILE_WRITE_DATA | FILE_APPEND_DATA | FILE_READ_EA | FILE_WRITE_EA | FILE_EXECUTE | FILE_DELETE_CHILD | FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES | Custom Security rights | |
CHANGE | = | FILE_GENERIC_WRITE | FILE_GENERIC_READ | FILE_EXECUTE | DELETE | ||
READ | = | FILE_GENERIC_READ | FILE_EXECUTE | ||
ADD | = | 0x001201bf | ||
SECURITY_RIGHTS | = | { 'FULL' => FULL, 'DELETE' => DELETE, 'READ' => READ, 'CHANGE' => CHANGE, 'ADD' => ADD |
basename | -> | basename_orig |
Strictly for making this code -w clean. They are removed later. | ||
blockdev? | -> | blockdev_orig |
chardev? | -> | chardev_orig |
dirname | -> | dirname_orig |
lstat | -> | lstat_orig |
size | -> | size_orig |
split | -> | split_orig |
stat | -> | stat_orig |
readonly? | -> | read_only? |
indexed? | -> | content_indexed? |
set_attributes | -> | set_attr |
remove_attributes | -> | unset_attr |
Returns true if the file or directory is an archive file. Applications use this attribute to mark files for backup or removal.
Returns an array of strings indicating the attributes for that file. The possible values are:
archive compressed directory encrypted hidden indexed normal offline readonly reparse_point sparse system temporary
Returns the last component of the filename given in filename. If suffix is given and present at the end of filename, it is removed. Any extension can be removed by giving an extension of ".*".
This was reimplemented because the current version does not handle UNC paths properly, i.e. it should not return anything less than the root. In all other respects it is identical to the current implementation.
File.basename("C:\foo\bar.txt") -> "bar.txt" File.basename("C:\foo\bar.txt", ".txt") -> "bar" File.basename("\\foo\bar") -> "\\foo\bar"
Returns whether or not file is a block device. For MS Windows this means a removable drive, cdrom or ramdisk.
Returns true if the file is a character device. This replaces the current Ruby implementation which always returns false.
Returns true if the file or directory is compressed. For a file, this means that all of the data in the file is compressed. For a directory, this means that compression is the default for newly created files and subdirectories.
Decrypts an encrypted file or directory.
The caller must have the FILE_READ_DATA, FILE_WRITE_DATA, FILE_READ_ATTRIBUTES, FILE_WRITE_ATTRIBUTES, and SYNCHRONIZE access rights.
Requires exclusive access to the file being decrypted, and will fail if another process is using the file. If the file is not encrypted an error is NOT raised.
Windows 2000 or later only.
Returns all components of the filename given in filename except the last one.
This was reimplemented because the current version does not handle UNC paths properly, i.e. it should not return anything less than the root. In all other respects it is identical to the current implementation.
File.dirname("C:\foo\bar\baz.txt") -> "C:\foo\bar" File.dirname("\\foo\bar") -> "\\foo\bar"
Encrypts a file or directory. All data streams in a file are encrypted. All new files created in an encrypted directory are encrypted.
The caller must have the FILE_READ_DATA, FILE_WRITE_DATA, FILE_READ_ATTRIBUTES, FILE_WRITE_ATTRIBUTES, and SYNCHRONIZE access rights.
Requires exclusive access to the file being encrypted, and will fail if another process is using the file. If the file is compressed, EncryptFile will decompress the file before encrypting it.
Windows 2000 or later only.
Returns true if the file or directory is encrypted. For a file, this means that all data in the file is encrypted. For a directory, this means that encryption is the default for newly created files and subdirectories.
Returns a hash describing the current file permissions for the given file. The account name is the key, and the value is an integer representing an or‘d value that corresponds to the security permissions for that file.
To get a human readable version of the permissions, pass the value to the +File.securities+ method.
Returns true if the file or directory is hidden. It is not included in an ordinary directory listing.
Returns file in long format. For example, if ‘SOMEFI~1.TXT’ was the argument provided, and the short representation for ‘somefile.txt’, then this method would return ‘somefile.txt’.
Note that certain file system optimizations may prevent this method from working as expected. In that case, you will get back the file name in 8.3 format.
Returns true if the data of the file is not immediately available. This attribute indicates that the file data has been physically moved to offline storage. This attribute is used by Remote Storage, the hierarchical storage management software. Applications should not arbitrarily change this attribute.
Returns true if The file or directory is read-only. Applications can read the file but cannot write to it or delete it. In the case of a directory, applications cannot delete it.
Returns true if the file or directory has an associated reparse point. A reparse point is a collection of user defined data associated with a file or directory. For more on reparse points, search msdn.microsoft.com.
Sets the file attributes based on the given (numeric) flags. This does not remove existing attributes, it merely adds to them.
Sets the file permissions for the given file name. The ‘permissions’ argument is a hash with an account name as the key, and the various permission constants as possible values. The possible constant values are:
FILE_READ_DATA FILE_WRITE_DATA FILE_APPEND_DATA FILE_READ_EA FILE_WRITE_EA FILE_EXECUTE FILE_DELETE_CHILD FILE_READ_ATTRIBUTES FILE_WRITE_ATTRIBUTES STANDARD_RIGHTS_ALL FULL READ ADD CHANGE DELETE READ_CONTROL WRITE_DAC WRITE_OWNER SYNCHRONIZE STANDARD_RIGHTS_REQUIRED STANDARD_RIGHTS_READ STANDARD_RIGHTS_WRITE STANDARD_RIGHTS_EXECUTE STANDARD_RIGHTS_ALL SPECIFIC_RIGHTS_ALL ACCESS_SYSTEM_SECURITY MAXIMUM_ALLOWED GENERIC_READ GENERIC_WRITE GENERIC_EXECUTE GENERIC_ALL
Returns ‘file_name’ in 8.3 format. For example, ‘c:\documentation.doc’ would be returned as ‘c:\docume~1.doc’.
Returns the size of the file in bytes.
This was reimplemented because the current version does not handle file sizes greater than 2gb.
Returns true if the file is a sparse file. A sparse file is a file in which much of the data is zeros, typically image files. See msdn.microsoft.com for more details.
Splits the given string into a directory and a file component and returns them in a two element array. This was reimplemented because the current version does not handle UNC paths properly.
Returns true if the file or directory is part of the operating system or is used exclusively by the operating system.
Returns true if the file is being used for temporary storage.
File systems avoid writing data back to mass storage if sufficient cache memory is available, because often the application deletes the temporary file shortly after the handle is closed. In that case, the system can entirely avoid writing the data. Otherwise, the data will be written after the handle is closed.
Sets the hidden attribute to true or false. Setting this attribute to true means that the file is not included in an ordinary directory listing.
Sets the ‘indexed’ attribute to true or false. Setting this to false means that the file will not be indexed by the content indexing service.
Sets the normal attribute. Note that only ‘true’ is a valid argument, which has the effect of removing most other attributes. Attempting to pass any value except true will raise an ArgumentError.
Sets whether or not a file is online or not. Setting this to false means that the data of the file is not immediately available. This attribute indicates that the file data has been physically moved to offline storage. This attribute is used by Remote Storage, the hierarchical storage management software.
Applications should not arbitrarily change this attribute.
Sets the readonly attribute. If set to true the the file or directory is readonly. Applications can read the file but cannot write to it or delete it. In the case of a directory, applications cannot delete it.
Sets the file to a sparse (usually image) file. Note that you cannot remove the sparse property from a file.
Set whether or not the file is a system file. A system file is a file that is part of the operating system or is used exclusively by it.
Sets whether or not the file is being used for temporary storage.
File systems avoid writing data back to mass storage if sufficient cache memory is available, because often the application deletes the temporary file shortly after the handle is closed. In that case, the system can entirely avoid writing the data. Otherwise, the data will be written after the handle is closed.