Skip to main content

Notifications

Announcements

No record found.

Find files in folder and subfolders

public container findFilesInFoldersAndSubFolder(String255 _folderPath)
{
InteropPermission permission;
permission = new InteropPermission(InteropKind::ClrInterop);
permission.assert();
boolean directoryExist = System.IO.Directory::Exists(_folderPath);
if(System.IO.File::Exists(_folderPath))
{
this.processFile(_folderPath);
}
else if(directoryExist)
{
this.processDir(_folderPath);
}
return mathchingFiles;
}

public void processFile(String255 filepath)
{
mathchingFiles = conins(mathchingFiles, conlen(mathchingFiles) + 1, filepath);
}

public void processDir(String255 _folderPath)
{
System.IO.DirectoryInfo directory,subDirectoryInfo;
System.IO.FileInfo[] files;
System.IO.FileInfo file;
System.IO.DirectoryInfo[] subDirectories;

str fileName;
counter filesCount,dirCount;
counter loop,loopSubDir;

directory = new System.IO.DirectoryInfo(_folderPath);
boolean directoryExist = System.IO.Directory::Exists(_folderPath);

files = directory.GetFiles();
filesCount = files.get_Length();
for (loop = 0; loop < filesCount; loop++)
{
file = files.GetValue(loop);
fileName = file.FullName;
this.processFile(fileName);
}
subDirectories = directory.GetDirectories();

dirCount = subDirectories.get_length();
for (loopSubDir = 0; loopSubDir < dirCount; loopSubDir++)
{
subDirectoryInfo = subDirectories.GetValue(loopSubDir);
str fullPath = subDirectoryInfo.FullName;
this.processDir(fullPath);
}
}

Comments

*This post is locked for comments