如何在批处理过程中获取文件夹中的文件? [英] How to get file in folder in batch process?

查看:108
本文介绍了如何在批处理过程中获取文件夹中的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在文件夹中获取文件.我的流程可以在批处理中使用.

I have to get file in a folder. My process can work in Batch.

我的代码是这样的:

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

My problem is for WinAPI.findFirstFile and WinAPI::findNextFile I have an error. How can I search in a folder,in batch process, the files ?

全部感谢

享受!

推荐答案

使用System.IO.DirectoryInfo并使用for循环遍历文件.只需将下面的文件夹路径替换为您的文件夹位置,它将生成该文件夹中所有文件的列表.

Use System.IO.DirectoryInfo and loop through the files with a for-loop. Just replace the folder path below with your folder' location, and it will generate a list of all the files inside the folder.

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();
}

这篇关于如何在批处理过程中获取文件夹中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆