Win32Forth


File and directory searching words.


These words are extensions to the ANSI file words for finding files.

If ior = 0, operation is O.K.; Otherwse, it is a failure.

Glossary

cell newuser _hdl-search ( -- addr )

Variable holding handle.

0  newuser _systemtime

Structure FileTimeToSystemTime function; this struc is same as time-buf in kernel.tom

: get-fspace { zroot \ clus freclus b/sec s/clus -- as bs cs ds }

Get a drive's free space, cluster and sector information "zroot" is the root directory spec zString for the desired drive in the format z" x:\", where x can be a, b, c, d or e etc...

: find-first-file ( addr1 len1 -- addr2 ior )

addr1 len1 is a string that specifies a valid directory or path and filename, which can contain wildcard characters (* and ?). This string must not exceed MAX_PATH characters. addr2 is the address of the _win32-find-data structure. ior is 0 for success in which case _hdl-search contains a valid handle.

Find-First-File searches a directory for a file whose name matches the specified filename. Find-First-File examines subdirectory names as well as filenames.

Find-First-File opens a search handle and returns information about the first file whose name matches the specified pattern. Once the search handle is established, you can use Find-Next-File to search for other files that match the same pattern. When the search handle is no longer needed, close it by using Find-Close. Find-First-File searches for files by name only; it cannot be used for attribute-based searches.

: find-next-file ( -- addr ior )

Find-first-file word must be called before this word can be called due to the fact that _hdl-search is needed

: find-close ( -- ior )

Close the _hdl-search handle.

: get-DOS-create-datetime ( -- ;convert 64 bit file time to MS_DOS )

Date and time values of creation.
You need to call find-first-file or find-next-file word in the current task before using this word.

: get-DOS-access-datetime ( -- ;convert 64 bit file time to MS_DOS )

date and time values of last access.
You need to call find-first-file or find-next-file word in the current task before using this word.

: get-DOS-write-datetime ( -- ;convert 64 bit file time to MS_DOS )

Date and time values of last write.
You need to call find-first-file or find-next-file word in the current task before using this word.

: get-file-size ( -- size )  \ W32F               Files Extra

Size of the last found file.
You need to call find-first-file or find-next-file word in the current task before using this word.

: get-file-name ( -- adr; address for file name )

get the name of the last found file.
You need to call find-first-file or find-next-file word in the current task before using this word.

: dir-attribute?  ( - flag )

Returns true when a file is a directory.
You need to call find-first-file or find-next-file word in the current task before using this word.
Can be used in combination with ForAllFileNames

2 cells newuser file-time-buf

2Variable to hold the FILETIME structure, which is a little endian (i.e. reversed order) 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601.

: dir->file-name ( -- adr count )

Returns the address and count of a file in a directory.
Need to call find-first-file or find-next-file word before using this word.
Can be used in combination with ForAllFileNames

: ForAllFileNames { cfa } ( adr slen cfa -- )

Executes the CFA for each found file in a directory.
A file specification adr slen may contain wildcards
NOTE: Directory names are also considered to be a file-name.
Directory names can be detected by dir-attribute?

: ForAllFiles     (  cfa -- )

Executes the CFA on ALL found files in a directory.
NOTE: Directory names are also considered to be a file-name.
Directory names can be detected by dir-attribute?

: .dir->file-size ( -- )

Print the size or directory indication of a file
Need to call find-first-file or find-next-file word before using this word.
Can be used in combination with ForAllFileNames

: .file-size-name  ( adr len - )

Print the size or directory indication and the name of file. It also formats the line.
Need to call find-first-file or find-next-file word before using this word.
Can be used in combination with ForAllFileNames

: print-dir-files ( adr slen -- ) \ W32F      Files Extra

Print all the files and sub-directories in a directory that match a specific pattern.

: dir           ( "name" -- )   \ W32F      Files Extra

Print all the files and sub-directories in a directory that match a specific pattern.
If "name" is missing or ends in \ or / search for all files that match *.*
If "name" contains a relative path then it's relative to the current directory.
If "name" ends in : assume a drive use "name"\*.* for the search pattern.

The pattern can contain the standard Windows wildcards.


Document $Id: p-ansfile.htm,v 1.1 2006/09/22 10:50:22 georgeahubert Exp $