Attachment 'WinFileDocumentation.html'

Download

WinFile (Class)

Version

Version 2.3.2 from 2012-10-05

Provides information about files and directories without using any .NET stuff.

Many methods (Dir+DirX for example) are MUCH faster than the .NET stuff.

The class contains shared methods only.

Almost all methods throw exceptions in case of an error.

Indexers

Note that there are fields available since version 1.7.0 useful to index the matrix returned by DirX . The field names start with "COL_" and "FA_" (for the file attributes). They assume a ⎕IO of 1. If you use ⎕IO←0 you have two options:

Use the

#.WinFile.((DirX'')[;COL_CreationDateName])

syntax or the

(#.WinFile.DirX '')[;COL_CreationDateName-~⎕IO]

syntax.

Kai Jaeger ⋄ APL Team Ltd

Homepage: http://aplwiki.com/WinFile

History

See: http://aplwiki.com/WinFile/ProjectPage

Go to: top

Reference

Included

APLTreeUtils

Fields

Go to: top

COL_CreationDateName

Shared, readonly

File creation date

Initialised with: 4

Go to: top

COL_LastAccessDate

Shared, readonly

Last access date

Initialised with: 5

Go to: top

COL_LastWriteDate

Shared, readonly

Last write date

Initialised with: 6

Go to: top

COL_Name

Shared, readonly

Full name

Initialised with: 1

Go to: top

COL_ShortName

Shared, readonly

8.3 name

Initialised with: 2

Go to: top

COL_Size

Shared, readonly

Size in bytes

Initialised with: 3

Go to: top

FA_ARCHIVE

Shared, readonly

32 0x20 A file or directory that is an archive file or directory.

Initialised with: 33

Go to: top

FA_COMPRESSED

Shared, readonly

2048 0x800 A file or directory that is compressed.

Initialised with: 27

Go to: top

FA_DEVICE

Shared, readonly

64 0x40 This value is reserved for system use.

Initialised with: 32

Go to: top

FA_DIRECTORY

Shared, readonly

16 0x10 Flag that identifies a directory.

Initialised with: 34

Go to: top

FA_ENCRYPTED

Shared, readonly

16384 0x4000 A file or directory that is encrypted.

Initialised with: 24

Go to: top

FA_HIDDEN

Shared, readonly

2 0x2 The file or directory is hidden. It is not included in an ordinary directory listing.

Initialised with: 36

Go to: top

FA_NORMAL

Shared, readonly

128 0x80 A file that does not have other attributes set.

Initialised with: 31

Go to: top

FA_NOT_CONTENT_INDEXED

Shared, readonly

8192 0x2000 The file or directory is not to be indexed by the content indexing service.

Initialised with: 25

Go to: top

FA_OFFLINE

Shared, readonly

4096 0x1000 The data of a file is not available immediately (offline storage).

Initialised with: 26

Go to: top

FA_READONLY

Shared, readonly

1 0x1 A file that is read-only.

Initialised with: 37

Go to: top

FA_REPARSE_POINT

Shared, readonly

1024 0x400 A file or directory that has an associated reparse point, or a file that is a symbolic link.

Initialised with: 28

Go to: top

FA_SPARSE_FILE

Shared, readonly

512 0x200 A file that is a sparse file.

Initialised with: 29

Go to: top

FA_SYSTEM

Shared, readonly

4 0x4 A file or directory that the operating system uses a part of, or uses exclusively.

Initialised with: 35

Go to: top

FA_TEMPORARY

Shared, readonly

256 0x100 A file that is being used for temporary storage.

Initialised with: 30

Go to: top

FA_VIRTUAL

Shared, readonly

65536 0x10000 This value is reserved for system use.

Initialised with: 22

Go to: top

okay

Shared, readonly

Initialised with: 0

Shared Methods

Go to: top

Cd

Syntax:R ← Cd Name

Report/change the current directory.

Go to: top

CheckPath

Syntax:R ← {NewFlag} CheckPath Path

Returns a 1 if the path to be checked is fine, otheriwse 0.

If the path does not exist but the left argument is "CREATE!" it will be created.

Go to: top

CopyToWithRC

Syntax:{(rc more)} ← Source CopyToWithRC Target

Copy "Source" to "Target".

The left argument must be a file. Wildcard characters are not supported. The right argument might be a filename or a folder. If it is a folder the filename of "Source" is used for the new file.

CopyTo always overwrites the target file if there is any.

Examples:

'C:\readme.txt' #.WinFile.CopyTo 'D:\buffer\'

'C:\readme.txt' #.WinFile.CopyTo 'D:\buffer\newname.txt'

When the "Copy" operation fails a DOMAIN ERROR is thrown.

The (shy) result r is always an empty vector in order to make CopyTo callable from a direct function.

If you prefer exceptions over return codes see CopyTo

Go to: top

CopyTo

Syntax:{r} ← Source CopyTo Target

Copy "Source" to "Target".

The left argument must be a file. Wildcard characters are not supported. The right argument might be a filename or a folder. If it is a folder the filename of "Source" is used for the new file.

CopyTo always overwrites the target file if there is any.

Examples:

'C:\readme.txt' #.WinFile.CopyTo 'D:\buffer\'

'C:\readme.txt' #.WinFile.CopyTo 'D:\buffer\newname.txt'

When the "Copy" operation fails a DOMAIN ERROR is thrown.

The (shy) result r is always an empty vector in order to make CopyTo callable from a direct function.

If you prefer return codes over throwing an exception see CopyToWithRC

Go to: top

DateOf

Syntax:R ← {Type} DateOf Filenames
Go to: top

Delete

Syntax:{Bool} ← Delete Filename

Delete one or more files.

Note that the explicit result tells you whether the file to be deleted existed upfront or not. It does not tell you whether the delete operation was successful or not. This is not a bug in WinFile , it is what the underlying Windows API function is returning. If you need to be sure that the file in question really got deleted use #.WinFile.DoesExistFile to find out.

Note that Delete does NOT support wildcards. If it finds wildcard chars it throws an error.

Go to: top

DirTree

Syntax:r ← DirTree path

Returns a vector of character vectors each representing a fully qualified path which is a sub=path of "path". Empty if "path" does not contain any directories.

Go to: top

DirX

Syntax:R ← {Parms} DirX Path

List the contents (names and attributes) of a given directory, by default the current one.

Pass "Recursive" as left argument to list all sub-directories, too.

By default, long names as well as short names together with file properties are returned but no timestamps. If you are in need for timestamps specify ('FileTime' 1) as left argument.

You can restrict the number of files returned by specifying ('NoOf' {anyNumber}).

Note that when a recursive scan is performed any wildcard chars in the right argument do effect the result list only but not the directories searched.

For example, this expression:

WinFile.DirX '*.svn'

returns a list with all files matching the pattern, even if they are contained in a sub-folder "abc" of the current dir which obviously doesn't match the pattern.

For addressing the file attributes see (and use) the FA_* and/or COL_* fields.

This example extracts the "Last write date" and the directory flag:

#.WinFile.((DirX '*')[;COL_LastWriteDate,FA_DIRECTORY])

Go to: top

Dir

Syntax:R ← {parms} Dir Path

List the contents (names only) of a given directory, by default the current one.

Pass "Recursive" as left argument to list all sub-directories, too.

Note that when "Recursive" is specified as left argument, any wildcard chars in the right argument do effect the result list only but not the the directories searched.

For example, this expression:

WinFile.Dir '*.svn'

returns a list with all directories matching the pattern, even if they are contained in a sub-folder "abc" of the current dir which obviously doesn't match the pattern.

Go to: top

DoesExistDir

Syntax:R ← {NewFlag} DoesExistDir Paths

Returns a Boolean for every dir in the right argument. The right argument can be one of:

  • Simple string. Treated as name of a single directory.
  • Vector of strings. Every item is treated as a directory name.

A 1 indicates that the corresponding directory exists.

Go to: top

DoesExistFile

Syntax:R ← DoesExistFile Filenames

Returns a Boolean for every file in the right argument. The right argument can be one of:

  • Simple string. Treated as name of a single filename.
  • Vector of strings. Every item is treated as a filename.

A 1 indicates that the corresponding file exists.

Go to: top

DoesExist

Syntax:R ← DoesExist pattern

Returns a Boolean for every file or directory in the right argument. The right argument can be one of:

  • Simple string. Treated as a single name (file or directory).
  • Vector of strings. Every item is treated as a name (file or directory).

A 1 indicates that the corresponding file or directory exists.

Go to: top

ExpandEnv

Syntax:R ← ExpandEnv Y

If Y does not contain any "%" Y is passed untouched.

In case Y is empty R is empty as well.

Example:

'C:\Windows\MyDir' ←→ #.WinSys.ExpandEnv '%WinDir%\MyDir'
'C:\Windows\'  ←→ #.WinSys.ExpandEnv '%WinDir%\MyDir\..'
Go to: top

ExpandPath

Syntax:r ← ExpandPath path

Expands "path" by replacing ".\" and "..\" with the real thing.

Go to: top

GetAllDrives

Syntax:R ← GetAllDrives

Return a vector of text vectors with the names of all drives, for example: "C:\"

Go to: top

GetDriveAndType

Syntax:R ← GetDriveAndType

Return a matrix with the names and the types of all drives.

The number of rows is defined by the number of drives found.

"Types" may be something like "Fixed", "CD-ROM", "Removable", "Remote"

Go to: top

GetTempFileName

Syntax:R ← {PrefixString} GetTempFileName PathName

Returns the name of an unused temporary filename. If "PathName" is empty, the default temp path is taken. This means you can overwrite this by specifying a path.

"PrefixString", if defined, is a leading string of the filename going to be generated. This is not the same as

'pref',GetTempFileName ''

because specified as left argument it is taken into account when the uniquness of the created filename is tested.

Go to: top

GetTempPath

Syntax:R ← GetTempPath

Returns the name of the path to the Windows temp directory on your system.

Go to: top

History

Syntax:r ← History
Go to: top

IsDirEmpty

Syntax:R ← IsDirEmpty Paths

Returns 1 if empty, 0 if not and ¯1 if the directory could not be found or is a file.

The right argument can be one of:

  • Simple string. Treated as a single name (file or directory).
  • Vector of strings. Every item is treated as a name (file or directory).
Go to: top

IsFilenameOkay

Syntax:r ← IsFilenameOkay filename

Returns a 1 in case "filename" is okay. "filename" must not have a path.

In order to check this a file with the given name is created in the temp folder.

Go to: top

IsFoldernameOkay

Syntax:r ← IsFoldernameOkay foldername

Returns a 1 in case "filename" is okay. "foldername" must not have a path.

In order to check this a directory "foldername" is created in the temp folder.

Go to: top

IsValidWin32Filename

Syntax:bool ← {noPath} IsValidWin32Filename filename

Checks whether "filename" is valid in terms of the Win32 sub-system.

Note that POSIX and NTFS rules are different!!

Note also that this function does not check for ":/\" which strictly speaking are not allowed in a filename but in a path.

If you want perform strict checking then specify "NoPath" as right argument. The left argument defaults to '', meaning that "filename" is considered to be a full path; that includes /\ as well as :.

Go to: top

ListDirsOnly

Syntax:R ← {Recursive} ListDirsOnly Path

Returns a list with all directories in "Path". In order to get also sub-directories specify "recursive" as left argument.

Wildcards are supported. Note that when used with "Recursive" as left argument the wildcards only affect the resulting list of directories but NOT the directories searched.

Examples:

ListDirsOnly '?.svn'          ⍝ Is there a dir ".svn" in the current dir? 
ListDirsOnly '*.acre'         ⍝ List all dirs ending with ".acre" in current dir 
ListDirsOnly 'ThisFolder'     ⍝ Assums "ThisFolder" is a dir & looks into it 
ListDirsOnly 'ThisFolder\'    ⍝ Same as before 
Go to: top

ListDirXIndices

Syntax:R ← ListDirXIndices

This function returns a matrix with all indices useful to index the result of DirX .

Note that these are the fields starting their names with COL_ .

Example to get the last write date:

(#.WinFile.DirX '*')[;#.WinFile.FA_HIDDEN]

The columns returned:

[;1] Name

[;2] Value (decimal)

[;3] Value (hex)

[;4] Remark

See also ListFileAttributes .

Go to: top

ListFileAttributes

Syntax:R ← ListFileAttributes

Returns a matrix with all fields starting their names with FA_ .

These are used to index the result of DirX in order to get a particular file attribute. For example. in order to find out whether a file is hidden or not:

(#.WinFile.DirX '*')[;#.WinFile.FA_HIDDEN]

These columns are returned:

[;1] Name

[;2] Value (decimal)

[;3] Value (hex)

[;4] Remark

See also ListDirXIndices .

Go to: top

MkDir

Syntax:{r} ← MkDir Name

Create (make) a new directory.

Result is always an empty vector.

Go to: top

MoveToWithRC

Syntax:{(rc more)} ← Source MoveToWithRC Target

Moves "Source" to "Target".

The function returns a return code and a textual message which is empty in case of success.

If you prefer an exception over a return code see MoveTo .

The left argument must be a file. Wilcard characters are not supported. The right argument might be a filename or a folder. If it is a folder the filename of "Source" is used for the new file.

MoveTo always overwrites the target file if there is any.

Examples:

'C:\readme.txt' #.WinFile.MoveTo 'D:\buffer\' 
'C:\readme.txt' #.WinFile.MoveTo 'D:\buffer\newname.txt' 
Go to: top

MoveTo

Syntax:{r} ← Source MoveTo Target

Moves "Source" to "Target".

In case of an error an exception is thrown. If you prefer a return code returned as explicit result see MoveToWithRC .

The explicit result is always an empty text vector.

The left argument must be a file. Wilcard characters are not supported. The right argument might be a filename or a folder. If it is a folder the filename of "Source" is used for the new file.

MoveTo always overwrites the target file if there is any.

Examples:

'C:\readme.txt' #.WinFile.MoveTo 'D:\buffer\' 
'C:\readme.txt' #.WinFile.MoveTo 'D:\buffer\newname.txt' 
Go to: top

PolishCurrentDir

Syntax:PolishCurrentDir

If ⎕WSID is relative (no "/" or "\" char in the path) the function does nothing.

Otherwise the current directory is changed to that it becomse the path part of ⎕WSID

Go to: top

PWD

Syntax:r ← PWD

Print Working Directory. Shortcut for Cd'' .

Go to: top

ReadAnsiFile

Syntax:R ← {noSplit} ReadAnsiFile filename

Read contents as chars. File is tied in shared mode.

Go to: top

RmDir

Syntax:{(r more)} ← {Recursive} RmDir Foldername

Removes an empty directory. If the left argument is "Recursive" then any files and sub-directories are deleted as well.

Since this operation might fail simply because another user is just looking into one of the directories going to be deleted, a boolean value is returned indicating success (0) or failure (positive error indicating the problem). As a second result "more" is returned.

Note that error 145 is returned on an attempt to delete a non-empty directory without specifying "Recursive" as left argument.

Go to: top

Version

Syntax:r ← Version
Go to: top

WriteAnsiFile

Syntax:{r} ← Data WriteAnsiFile filename

Data must be a string or a vector of strings. If file already exists it is replaced.

Go to: top

YoungerThan

Syntax:R ← Filename1 YoungerThan Filename2

Compare the "last changed at" timestamp of both, Filename1 and Filename2 .



Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2015-01-27 14:26:37, 38.5 KB) [[attachment:WinFileDocumentation.html]]
 All files | Selected Files: delete move to page

You are not allowed to attach a file to this page.