mac100
mac100

Reputation: 137

How to read all the files from a directory and move files to another directory in progress openedge 4gl?

I need to read the contents of all the files in a folder , one at a time and move the file to another folder once it is read. I have hardcoded to read a single file . copy-lob from file "E:\New\a.txt" to c-edistring .

Say there are three files a.txt , b.txt , c.txt .

Once a.txt is read the file should be moved to another folder E:\Old. followed by b and c .

Upvotes: 0

Views: 2540

Answers (2)

Tim Kuehn
Tim Kuehn

Reputation: 3251

Years ago I wrote a tools program to do what you want - you can get a copy here: https://community.progress.com/community_groups/openedge_general/w/openedgegeneral/1615.directory-tools

Upvotes: 1

Mike Fechner
Mike Fechner

Reputation: 7192

The INPUT FROM OS-DIR Statement allows you to retrieve a list of all files in a folder.

DEFINE VARIABLE cFileShort AS CHARACTER NO-UNDO .
DEFINE VARIABLE cFileLong  AS CHARACTER NO-UNDO.
DEFINE VARIABLE cType      AS CHARACTER NO-UNDO.

INPUT FROM OS-DIR ("e:\New") .

REPEAT:
    IMPORT cFileShort cFileLong cType . 

    /* File or Directory ? */
    IF cType MATCHES "*F*" THEN 
        MESSAGE "ShortFileName" cFileShort SKIP
                "LongFileName" cFileLong .

END.    

To move the files, you do not need to use COPY-LOB, which copies the file contents into memory.

OS-COPY VALUE (cFileLong) VALUE (SUBSTITUTE ("e:\Old\&1", cFileShort) .
IF OS-ERROR = 0 THEN 
    OS-DELETE VALUE (cFileLong) . 

within the loop above will do the move without reading the complete files into memory.

When you can count on .NET (Windows, OpenEdge 10.2B and above) you can also use .NET classes for file operations, similar to https://msdn.microsoft.com/en-us/library/cc148994(v=vs.100).aspx

Upvotes: 3

Related Questions