【问题标题】:How to get file in folder in batch process?如何在批处理中获取文件夹中的文件?
【发布时间】:2015-12-30 09:18:35
【问题描述】:

我必须在文件夹中获取文件。我的流程可以批量工作。

我的代码是这样的:

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.findFirstFileWinAPI::findNextFile 我有一个错误。 如何在文件夹中,在批处理过程中搜索文件?

谢谢大家,

享受吧!

【问题讨论】:

标签: file batch-processing axapta dynamics-ax-2012 x++


【解决方案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();
}

【讨论】:

  • 好@TinavanderVyver,以及获得名称tmpFileNameShort的好解决方案。好好工作!谢谢。新年快乐!
猜你喜欢
  • 2013-05-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多