FileSystem
When you are using Standard Import Routine pre-macros, in many cases a Dir command has to be used. IDEAScript provides a Dir command but this command does not working for specific configured SSD drives and directories using advanced attributes like "compress contents ..." and "encrypted contents ...". With the following functionality a user can search for files on any drive.
The MacroCommands interface gets a new object FileSystem which has the following properties and methods:
fileList GetFiles(string path, string searchPattern, optional int searchOption = TopDirectoryOnly)
fileList GetFolders(string path, string searchPattern, optional int searchOption = TopDirectoryOnly)
fileList GetFilesByRegEx(string path, string searchPattern, optional int searchOption = TopDirectoryOnly)
This function provides a corresponding list of file objects identified on a regular expression.
You can use For Each to iterate all individual file objects inside the fileList object.
The file object has the following properties:
| Property | Description |
|---|---|
|
Name |
File name without path. |
|
Relative path |
File name with relative path corresponding to the current IDEA project. |
|
Path |
File name with full path. |
|
Size |
File size in bytes. |
Example
Option Explicit
Const TopDirectoryOnly = 0
Const AllDirectories = 1
Sub Main
on error go to erh
Dim oFiles AS Object
Dim oFile As Object
Dim fs As Object
Set fs = SmartContext.MacroCommands.GetFileSystem()
Set oFiles = fs.GetFiles("c:\temp", "*", TopDirectoryOnly)
For Each oFile In oFiles
MsgBox oFile.Name & Chr(10) & oFile.Path & Chr(10) & oFile.RelativePath & Chr(10) & oFile.Size
Next
Set oFiles = fs.GetFolders("c:\temp", "*", AllDirectories)
For Each oFile In oFiles
MsgBox oFile.Name & Chr(10) & oFile.Path & Chr(10) & oFile.RelativePath & Chr(10) & oFile.Size
Next
'Now using regular expression
Set oFiles = fs.GetFilesByRegEx("c:\temp", "*", AllDirectories)
For Each oFile In oFiles
MsgBox oFile.Name & Chr(10) & oFile.Path & Chr(10) & oFile.RelativePath & Chr(10) & oFile.Size
Next
Exit Sub
erh.
MsgBox "error " & err.Description
End Sub