Class FileSystem
- Namespace
- TwinSharp
- Assembly
- TwinSharp.dll
The FileSystem class provides methods for interacting with the file system on a target device using the TwinCAT ADS protocol. It allows opening, closing, reading, writing, seeking, deleting files, as well as creating and deleting directories.
public class FileSystem : IDisposable
- Inheritance
-
FileSystem
- Implements
- Inherited Members
Methods
CreateDirectory(string)
Create a new folder on the target. Note: does not create folders recursively.
public void CreateDirectory(string path)
Parameters
path
string
CreateFileFinder(string)
Use a file finder to search for files on target device.
public FileFinder CreateFileFinder(string searchQuery)
Parameters
searchQuery
stringA valid directory name or directory with file name as string. The string can contain (* and ? ) as wildcards. If the path ends with a wildcard, dot or the directory name, the user must have access rights to this path and its subdirectories.
Returns
DeleteDirectory(string)
Can be used to delete a directory from the data storage device. A directory containing files cannot be deleted. Equivavalent to the function block FB_RemoveDir.
public void DeleteDirectory(string path)
Parameters
path
string
Dispose()
Disposes the File System object. Disposes the ADS client used.
public void Dispose()
FileClose(ushort)
The function block FB_FileClose closes the file, thereby putting it in a defined state for further processing by other programs. Equivavelent to the TwinCAT function block FB_FileClose.
public void FileClose(ushort handle)
Parameters
handle
ushort
FileDelete(string)
Deletes a file from the data storage device. Equivavalent to the function block FB_FileDelete.
public void FileDelete(string pathName)
Parameters
pathName
stringFile name, including the full path.
FileGetString(ushort, out bool)
Reads strings from a file. The string is read up to and including the line feed character, or up to the end of the file or the maximum permitted length of sLine. The null termination is appended automatically. The file must have been opened in text mode. Equivavelent to the function block FB_FileGets.
public string FileGetString(ushort handle, out bool endOfFile)
Parameters
Returns
FileOpen(string, FileOpenModeFlags)
Creates a new file or opens an existing file for editing. Equivavelent to the TwinCAT function block FB_FileOpen
public ushort FileOpen(string path, FileOpenModeFlags mode)
Parameters
path
stringmode
FileOpenModeFlags
Returns
FilePutString(ushort, string)
Writes strings into a file. The string is written to the file up to the null termination, but without the null character. The file must have been opened in text mode. Equivalent to the function block FB_FilePuts
public void FilePutString(ushort fileHandle, string str)
Parameters
FileRead(ushort, int)
The contents of an already opened file can be read. Before a read access, the file must have been opened in the corresponding mode. In addition to the FOPEN_MODEREAD, the appropriate format (FOPEN_MODEBINARY or FOPEN_MODETEXT) is also important to achieve the desired result. Equivavalent to the function block FB_FileRead.
public byte[] FileRead(ushort handle, int byteCountToRead)
Parameters
Returns
- byte[]
FileRename(string, string)
Can be used to rename a file. Equivavalent to the function block FB_FileRename.
public void FileRename(string oldPath, string newPath)
Parameters
FileSeek(ushort, int, SeekOrigin)
Sets the file pointer of an open file to a definable position. Equivavalent to the function block FB_FileSeek.
public void FileSeek(ushort handle, int position, SeekOrigin origin)
Parameters
handle
ushortposition
intorigin
SeekOrigin
FileTell(uint)
Determines the current position of the file pointer. The position indicates the relative offset from the start of the file. Equivavalent to the function block FB_FileTell. Note that for files opened in "Append at end of file" mode, the current position is determined by the last I/O operation, not by the position of the next write access. After a read operation, for example, the file pointer is at the position where the next read access will take place, not at the position where the next write access will take place. In append mode, the file pointer is always moved to the end before the write operation. If no previous I/O operation was performed and the file was opened in append mode, the file pointer is at the start of the file.
public int FileTell(uint handle)
Parameters
handle
uint
Returns
- int
The current position of the file pointer.
FileWrite(ushort, byte[])
Writes data into a file. For write access the file must have been opened in the corresponding mode, and it must be closed again for further processing by external programs. Equivalent to the function block FB_FileWrite.
public uint FileWrite(ushort handle, byte[] data)
Parameters
Returns
- uint
The number of bytes that were sucessfully written.
GetFileProperties(string)
public ST_FindFileEntry GetFileProperties(string path)
Parameters
path
string