0

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

My code is this:

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....
}

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 ?

Thansk all,

enjoy!

ulisses
  • 1,549
  • 3
  • 37
  • 85
  • Did you check [Try to use Winapi::findFirstFile running on server](http://stackoverflow.com/questions/8300111/try-to-use-winapifindfirstfile-running-on-Server)? It sounds very similar. Please always include the actual error message in your questions. – FH-Inway Dec 30 '15 at 12:36

1 Answers1

1

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();
}
  • good @TinavanderVyver, and good solution to get name tmpFileNameShort. Work well! Thanks. Happy new year! – ulisses Dec 31 '15 at 01:02