To rebuild the directory structure, following steps are required:
1) Use prolib -list command to list the contents of the library.
2) From the output, identify file/directory structure - files will be listed as relative path references; the relative paths must be re-created on the file system, in the location where the prolib is run.
3) Use prolib -extract command to extract the contents of the library.
This can be automated via shell script or program.
One example using the OpenEdge ABL:
DEFINE TEMP-TABLE dirtree NO-UNDO
FIELD dirname AS CHARACTER FORMAT "X(40)"
FIELD dirlevel AS INTEGER
INDEX dirname IS UNIQUE dirname
INDEX dirlevel IS PRIMARY dirlevel.
/* test stub: pick a library that's normally shipped with the product */
RUN ExtractWithDirectories (INPUT "%DLC%/tty/prodict.pl").
/* the bulk of the logic */
PROCEDURE ExtractWithDirectories:
DEFINE INPUT PARAMETER cLibrarypath AS CHARACTER NO-UNDO.
DEF VAR cEntry AS CHAR NO-UNDO.
DEF VAR iCount AS INT NO-UNDO.
INPUT THROUGH VALUE("prolib " + cLibrarypath + " -list").
DO icount = 1 TO 4: /* just ignore the first 4 lines - those are header details */
IMPORT UNFORMATTED cEntry.
END.
REPEAT:
IMPORT UNFORMATTED cEntry.
IF TRIM(cEntry) = "" THEN LEAVE.
/* normalize path name to get rid of the Windows vs. Unix difference in notation. Because both are valid in a .pl. */
cEntry = REPLACE(cEntry,"\","/").
/* Last 7 tokens are Size,Type,Offset, Modified and Added To Lib stuff, not path names.
Get rid of those in a way that handles:
- variable length lines
- variable file extensions (including no extension, so can't rely on for period "." being present in path)
- variable number of subdirectories (including no subdirectories, so can't rely on "/" or "\" being present in path)
- spaces in path name (so can't rely on first space on the line read).
*/
DO icount = 1 TO 7:
ENTRY(NUM-ENTRIES(cEntry," "),cEntry," ") = "".
cEntry = RIGHT-TRIM(centry).
END.
/* cut off the actual file name */
ENTRY(NUM-ENTRIES(cEntry,"/"),cEntry,"/") = "".
cEntry = RIGHT-TRIM(centry, "/").
/* Build the list of unique directory names found in the library.
Do a multi-pass here to make sure that all parent directories are accounted for as well.
*/
REPEAT:
IF cEntry = "" THEN LEAVE. /* passed top of hierarchy */
IF CAN-FIND(dirtree WHERE dirname = cEntry) THEN LEAVE. /* or found a parent that was added based on earlier entry */
CREATE dirtree.
ASSIGN
dirname = cEntry
dirlevel = NUM-ENTRIES(cEntry,"/").
ENTRY(NUM-ENTRIES(cEntry,"/"),cEntry,"/") = "".
cEntry = RIGHT-TRIM(centry, "/").
END.
END.
INPUT close.
/* with all that figured out, build directory structure by level of the hierarchy */
FOR EACH dirtree BY dirlevel:
OS-CREATE-DIR value(dirname).
IF OS-ERROR <> 0 THEN RETURN ERROR "Could not build directory structure".
END.
/* and finally, let the prolib -extract do it's job */
OS-COMMAND SILENT(VALUE("prolib " + cLibrarypath + " -nowarn -extract *")).
END.
The logic above is used in the (attached) Prolib GUI tool.
To use the Prolib GUI tool:
- Extract the contents of prolib.zip
- Run prolib\prolib.w
- Enjoy
Note: The following Idea was logged in Aha for prolib to automatically create the directory structure when performing an -extract or -yank operation.
https://openedge.ideas.aha.io/ideas/OPENEDGE-I-51