• Welcome to OS2World OLD-STATIC-BACKUP Forum.
 

News:

This is an old OS2World backup forum for reference only. IT IS READ ONLY!!!

If you need help with OS/2 - eComStation visit http://www.os2world.com/forum

Main Menu

Search for files create folder with shadows

Started by jep, 2009.05.26, 12:02:45

Previous topic - Next topic

jep

Marked as: Normal
Hi,

the hdd of my main computer encountered a problem and went into "bricked" state¹, but now I'm back on track again.

C:\*.cmd

This time I'd like to show you how to mimic parts of the included WPS Search procedure. It's not meant to give you all of the possible selections, bells and whistles as the real thing, but show you how to parse a parameter and create shadows on the desktop, present progress and info about folders processed while still be responsive as it search a drive.
The code also contain a small, but quite useful, rexx .dll called MKey that provide functionality to wait for a key to be pressed within x number of milliseconds. Go to Hobbes and search for MKey.

It's heavily based on previous recursive examples with progressbars etc, while adjusted to handle this specific task, something that is quite useful when one use rexx. Reuse of code can help you as a developer to minimize the time spent to get the useful helping tool you need.

/* Script: Find all files in specified directory and subdirectories to destination (folder) and create a folder with shadows on the desktop for it. */

currdir = strip( DIRECTORY(), 'T', '\' )
numwords = 0

CALL rxFuncAdd "SysLoadFuncs" , "RexxUtil" , "SysLoadFuncs"
CALL SysLoadFuncs

CALL RxFuncAdd "MKey","MKey","MKey"

CALL SysCls
IF ARG() = 0 THEN
    Return Usage()

IF ARG(1) = '' THEN
    pattern = '*'
ELSE DO
    from = STRIP( FILESPEC( 'D', ARG(1) )||FILESPEC( 'P', ARG(1) ), 'T', '\' )
    pattern = FILESPEC( 'N', ARG(1) )
END
IF from = '' THEN
    from = DIRECTORY()


CALL rxBusy 'Loading, one moment please...', 0

elapsed = TIME( 'R' )
wp_folder = SysTempFileName( 'WP_SEARCH_???' )
If SysCreateObject( "WPFolder", ARG(1), "<WP_DESKTOP>", "OBJECTID=<"||wp_folder||">;ICONFILE="||DIRECTORY()||"\Search_Folder.ICO" ) then
    IF SysOpenObject( '<'||wp_folder||'>', DEFAULT, 1 ) THEN
CALL processPath from, pattern, 0, 1
CALL rxProgress 1, 2
CALL DIRECTORY currdir
EXIT 0

processPath: PROCEDURE EXPOSE elapsed counter_ wp_folder
    wp_source = ARG(1)
    wp_pattern = ARG(2)
    progress = ARG(3)
    chunk = ARG(4)

    CALL SysFileTree wp_source||'\*', 'folder', 'DO'
    CALL SysFileTree wp_source||'\'||wp_pattern, 'file', 'FO'
   
    IF MKey( 1000 ) = 1 THEN
        PARSE PULL dont_process_this_folder
    ELSE DO j = 1 to folder.0
        IF TIME( 'E' ) > 1 + elapsed THEN DO
            CALL rxBusy 'Processing '||folder.j, 0
            CALL rxProgress progress + ( j - 1 ) / ( folder.0 + file.0 ) * chunk, 2
            elapsed = TIME( 'E' )
        END
        wp_star_pos = POS( '*', wp_pattern )
counter = 1
        DO WHILE wp_star_pos > 0
            wp_pattern = SUBSTR( wp_pattern, 1, wp_star_pos - 1 )||'"pre.'||counter||'"'||SUBSTR( wp_pattern, wp_star_pos + 1 )
            counter = counter + 1
            wp_star_pos = POS( '*', wp_pattern )
        END
counter = counter - 1
        INTERPRET 'PARSE VALUE folder.j WITH "'||wp_pattern||'"'
       
        IF LENGTH( pre.counter ) > 0 & counter > 0 THEN
            call SysCreateShadow folder.j,'<'||wp_folder||'>'
       
        CALL processPath folder.j, ARG(2), progress + ( j - 1 ) / ( folder.0 + file.0 ) * chunk, chunk / ( folder.0 + file.0 )
    END
    DROP folder.

    DO i = 1 to file.0
        IF TIME( 'E' ) > 1 + elapsed THEN DO
            CALL rxBusy 'Processing '||wp_source, 0
            CALL rxProgress progress + ( j + i - 1 ) / ( j + file.0 ) * chunk, 2
            elapsed = TIME( 'E' )
        END
        rc = SysCreateShadow( file.i, '<'||wp_folder||'>' )
    END
    DROP file.
RETURN

/* part, of_total, display_on_row */
rxProgress: PROCEDURE
    IF DATATYPE( ARG(1), 'N' ) THEN
    DO
        progress = MIN( TRUNC( 76 * ARG(1) ), 76 )
        CALL rxOut LEFT( COPIES( '█', progress )||COPIES( '?', 76 - progress ), 76 )||RIGHT( TRUNC( 100 * ARG(1) )||'%', 4 ), ARG(2)
    END
Return 0

rxBusy: PROCEDURE EXPOSE counter_
    SELECT
        WHEN counter_ = 1 THEN
            CALL rxOut '/ '||ARG(1), ARG(2)
        WHEN counter_ = 2 THEN
            CALL rxOut '- '||ARG(1), ARG(2)
        WHEN counter_ = 3  THEN
            CALL rxOut '\ '||ARG(1), ARG(2)
        OTHERWISE
        counter_ = 0
        CALL rxOut '| '||ARG(1), ARG(2)
    END
    counter_ = counter_ + 1
Return 0

/* text, display_on_row */
rxOut: PROCEDURE
    IF DATATYPE( ARG(2), 'W' ) THEN
        PARSE VALUE SysCurPos( ARG(2), 0 ) with prev_row prev_col
    SAY LEFT( ARG(1), 80 )
    IF DATATYPE( ARG(2), 'W' ) THEN
        CALL SysCurPos prev_row, prev_col
Return 0



¹) All data was supposedly intact, though some internal counter went 1 tick to far so the built in saftey procedures locked the drive after 321 power on/offs due to some manufacturing error.