我必须在文件夹中获取文件。我的流程可以在批处理中使用。
我的代码是:
Io file;
FileIoPermission perm;
int handle;
Filename fileName;
[handle, filename] = WINAPI::findFirstFile( myFilePatch + "\\*.txt");
fileOpen = strFmt (myFilePatch + "\\" + filename);
if (filename)
{
perm = new FileIoPermission(filename, 'r');
perm.assert();
file = new TextIo(filename, 'r', 65001);
}
//etc... other code
// I go on to find another file
filename = WinAPI::findNextFile(handle);
fileOpen = strFmt (myFilePatch + "\\" + filename);
if (filename)
{
// open file....
}
我的问题是WinAPI.findFirstFile
和WinAPI::findNextFile
我有错误。
如何在批处理文件夹中搜索文件夹?
Thansk all,
享受!
答案 0 :(得分:1)
使用System.IO.DirectoryInfo并使用for循环遍历文件。只需用文件夹的位置替换下面的文件夹路径,它就会生成文件夹中所有文件的列表。
static void loopDirectory(Args _args)
{
System.IO.DirectoryInfo directory;
System.IO.FileInfo[] files;
System.IO.FileInfo file;
InteropPermission permission;
Filename tmpFilePath;
Filename tmpFileNameShort;
Filename tmpFileExt;
str fileNameTemp;
counter filesCount;
counter loop;
permission = new InteropPermission(InteropKind::ClrInterop);
permission.assert();
directory = new System.IO.DirectoryInfo(@"C:\Users...");
files = directory.GetFiles();
filesCount = files.get_Length();
for (loop = 0; loop < filesCount; loop++)
{
file = files.GetValue(loop);
fileNameTemp = file.get_FullName();
[tmpFilePath, tmpFileNameShort, tmpFileExt] = fileNameSplit(fileNameTemp);
info(tmpFileNameShort);
}
CodeAccessPermission::revertAssert();
}