Topic: DMD0388

Help File Version: 2.10.0.636

FILEQUERY - Query File or Folder Information


The Query File or Folder Information (FILEQUERY) instruction is used to retrieve status information about the files and folders on a file system - see example #1 below. This instruction can also be used to generate a list of the folders and files on a file system - see example #2 below.

 

 

File System selects which of the available file systems to use:

@RamFS is the 1 MB file system in the Do-more CPU's system RAM. All Do-more CPUs will have this file system available.

 

@SDCardFS is the file system on the removable media installed in the micro-SD card slot (BRX only). This file system is automatically created when the removable media is inserted into the micro-SD card slot. The $SDCardFS.MediaInstalled and $SDCardFS.MediaMounted structure elements will be ON if there is a functional file system available on media in the micro-SD slot.

Note: All micro-SD media must be formatted in a PC before it can be used in a Do-more CPU. Only micro-SD media which has been formatted as FAT32 is supported. The file system can only access the first 32GB of storage space on the micro-SD media; any micro-SD card that is larger than 32GB must be reformatted to FAT32 before it can be used.

Query File / Folder Name - the full path (including any directories) of the file on the specified file system. This can be text enclosed in double quotes, or any system or user-defined string. The File Name allows a maximum length of 255 characters including spaces and non-alphanumeric characters, excluding the following characters which have special meaning to the file system * ? " : < > | .

 


File Date as 1970 Epoch - the date the file was last written to. The value is a 1970 EpochClosed The number of seconds that have elapsed since 12:00:00PM, January 1, 1970. An epoch is an instant in time chosen as the origin of a particular era. The "epoch" then serves as a reference point from which time is measured. Time measurement units are counted from the epoch so that the date and time of events can be specified unambiguously. number which is the number of seconds of time that have elapsed since midnight at Jan 1 1970. This can be any writable numeric location.

 

File Size in Bytes - the total number of bytes the file consumes on the file system. This can be any writable numeric location.

 

File Attributes - a DWord where the individual Bits indicate attributes of the file as described below. This can be any writable numeric location.

Bit 0: Read Only - if this bit is ON the file cannot be added to or overwritten, only read. The attribute's main purpose is to prevent accidental changes to important files. It also prevents deletion of the file by the FILEDEL - Delete File command.

 

Bit 1: Hidden - if this bit is ON the file is invisible to directory searches.

 

Bit 2: System - if this Bit is ON the file is deemed critical because it is used by the Windows operating system. As with the read-only attribute, the system attribute prevents the file from being altered, moved, or deleted.

 

Bit 3: Volume Label - if this Bit is ON the file is the Volume Label. FAT32 can mark one file in the root directory as a volume label. When you initialize a disk drive with the format command, it prompts you for an optional volume name, which helps distinguish the disk's contents. If you type in a volume label, FAT32 creates a file with that as its name and marks it with the volume label attribute.

 

Bit 4: Directory - if this Bit is ON the entry is understood to be a directory, not a file. The root directory can have any number of files and sub-directories, and each sub-directory can, in turn, contain files and sub-directories. Sub-directories have a file size of zero.

 

Bit 5: Archive - this Bit is set ON as soon as the file is created or any time the file is modified.

 

Bit 6 - Bit 31: Unused by BRX - n/a.

Actual File Name - the fully qualified file name as stored on the file system. This can be any of the system-defined Short Strings, system-defined Long Strings, or user-defined String.

 


The following parameters are only used to iterate the folders and files in the folder specified in Query Folder / File Name parameter. This does not iterate through any sub-folders that exist, it only iterates the contents of the currently selected folder. The iteration process requires using the <File System>.StartFolderScan, <File System>.StopFolderScan, and <File System>.FolderEntryNum structure members. Refer to Example #2 below for their proper usage.

 

Iterate Folder - enable this option to generate a list of sub-folders and files within the specified folder..

 

  • Files Only - list only the files found, any folders will be skipped.

  • Folders Only - list only folders, any files found in those folders will be skipped.

  • Files and Folders - list files and folders.

 

Found File / Folder - after each step in the iteration, this String will contain the name of the folder or file that was found.

 

Iteration Index - if enabled, the value in <File System>.FolderEntryNum - which contains the number of folders and / or files that were found - is copied here after the iteration is complete,

 


The On Success and On Error parameters specify what action to perform when this instruction completes. You do not have to use the same type of selection for both On Success and On Error.

 

If the Set Bit selection is used for either On Success or On Error, the specified BIT location will be SET OFF when the instruction is first enabled and will remain OFF until the instruction completes. Once complete, the appropriate Success or Error bit location will be set ON. The specified Bit location is enabled with a SET (Latch) operation (not an OUT operation) meaning that it will remain ON even if this instruction's input logic goes OFF.

 

If the JMP to Stage selection is used for either On Success or On Error the target Stage must be in the same Program code-block as this instruction, you cannot specify a target Stage that exists in a different Program code-block. When the operation finishes, the target Stage will be enabled the same way as a standalone Jump to Stage (JMP) instruction would do it. The JMP to Stage option will only be selectable if this instruction is placed in a Program code-block.

 

On Success selects which of the following actions to perform if the operation is successful:

  • Enable Set Bit then specify any writable bit location.
  • Enable JMP to Stage then specify any Stage number from S0 to S127 in the current Program code-block.

 

On Error selects which of the following actions to perform if the operation is unsuccessful:

  • Enable SET Bit then specify writable bit location.
  • Enable JMP to Stage then specify any Stage number from S0 to S127 in the current Program code-block.

 

If either the On Success or On Error selections are set to JMP to Stage, Automatically create the SG box for any NEW stage number will be enabled which will automatically create any target stage that does not already exist.

  • Below this rung will create the new target stage on a new rung following this instruction.
  • At end of code-block will create the new target stage on the last rung of this Program.

 


Error Codes

Improper use of any FILE instruction or any file system hardware problem will generate a warning message at runtime. When any of these warnings are generated, the On Error parameter in the instruction will be ON and the System ERR variable will contain one of the following text messages. You will also be alerted to this condition by yellow "Warning" text displayed in the Status Bar of Do-more Designer. Clicking that text will open the System Status to display the full text of the warning message.

 

 

Text displayed in the ERR System variable

 

How To Solve / What To Do

SdCard not installed, or has an error

 

On PLC systems that have an SD Card slot, this indicates the SD card is either missing or an error occurred while trying to mount the file system on that media.

 

Note: you can use the File System structure's .MediaInstalled and .MediaMounted in permissive contacts with the input logic of the FILEOPEN instruction to make sure the removable media is properly installed and available before an attempt is made to execute the instruction.

 

File wasn't found

 

The File Name specified could not be located not on the specified File System. It could be spelled wrong, or it could be located in a sub-folder that is not specified, or located on a different File System.

 

File access denied

 

An attempt to open a file for Create / Append that is marked as either Read-Only or as a System file.

 

Attempted to open a device that is already open

 

An attempt was made to open a file that is currently open with a different File Handle or an attempt was made to open a file with a File Handle that is currently in use.

 

File system is full

 

An attempt was made to open a file for Create / Append but there is insufficient space on the specified File System to perform the operation.

 

Unknown error

 

An attempt to open a file in a folder when that folder does not exist, for example trying to open \MyFolder\MyFile.txt when \MyFolder doesn’t exist.

 

 


Status Display

 

The red triangle in the upper left corner of the status display indicates this is a Fully Asynchronous instruction.

 

The gray triangle at the right end of the input leg indicates the input is edge-triggered, meaning this instruction will execute each time the input logic transitions from OFF to ON.

 


See Also

FILECLOSE - Close File

 

FILECOPY - Copy File

 

FILEDEL - Delete File

 

FILELOG - Log to File

 

FILENEWFLDR - Make New Folder

 

FILEOPEN - Open File

 

FILEQUERY - Query File or Folder Information

 

FILEREAD - Read from File

 

FILESEEK - Seek to Position in File

 

FILESYSCMD - Perform File System Command

 

FILETRUNC - Truncate File

 

FILEWRITE - Write to File

 

EMAIL - Send Email (with file attachment)

 


Related Topics

File System Reference

 

Browse PLC File Systems

 


Example #1: Query for File Information


Example #2: Iterate the Contents of a Folder