A use case for System.IO fileinfo.

Posted by OctavioOlguin on 23-Sep-2015 19:04

Greetings.

Can some one help to transalate this:

DEFINE INPUT  PARAMETER RUTA     AS CHAR NO-UNDO.
DEFINE OUTPUT PARAMETER NOMARCH  AS CHAR NO-UNDO.
DEFINE OUTPUT PARAMETER EXTARCH  AS CHAR NO-UNDO.

DEFINE VAR I AS INTEGER NO-UNDO.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK 

/* ********************  Preprocessor Definitions  ******************** */

&Scoped-define PROCEDURE-TYPE Procedure
&Scoped-define DB-AWARE no



/* _UIB-PREPROCESSOR-BLOCK-END */
&ANALYZE-RESUME



/* *********************** Procedure Settings ************************ */

&ANALYZE-SUSPEND _PROCEDURE-SETTINGS
/* Settings for THIS-PROCEDURE
   Type: Procedure
   Allow: 
   Frames: 0
   Add Fields to: Neither
   Other Settings: CODE-ONLY COMPILE
 */
&ANALYZE-RESUME _END-PROCEDURE-SETTINGS

/* *************************  Create Window  ************************** */

&ANALYZE-SUSPEND _CREATE-WINDOW
/* DESIGN Window definition (used by the UIB) 
  CREATE WINDOW Procedure ASSIGN
         HEIGHT             = 3.67
         WIDTH              = 63.4.
/* END WINDOW DEFINITION */
                                                                        */
&ANALYZE-RESUME

 


&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Procedure 


/* ***************************  Main Block  *************************** */


/* First:  strip disc if present */
I = INDEX(RUTA, ":").
IF I > 0 THEN RUTA = SUBSTRING(RUTA, I + 1).

/* get filename, if there is extension...*/

I = INDEX(RUTA, ".").

IF I > 0 THEN DO:
    EXTARCH  = SUBSTRING(RUTA, I + 1).
    RUTA    = SUBSTRING(RUTA, 1, I - 1).
END.

ASSIGN I = R-INDEX(RUTA, "\").
IF I = 0 THEN DO:
    ASSIGN I = R-INDEX(RUTA, "/").
END.
IF I > 0 
THEN NOMARCH = SUBSTRING(RUTA, I + 1).
ELSE NOMARCH = RUTA.

RETURN.


into some method of system.IO, if available?

the object of procedure is to get just filename of a FQFN.  On other procedure I have same kind of logic to get just the extensión..

TIA

Jorge Octavio

All Replies

Posted by Garry Hall on 23-Sep-2015 20:24

Are you looking for System.IO.Path:GetFileName()?

Posted by tbergman on 24-Sep-2015 05:25

USING System.IO.*.

DEFINE VARIABLE vFile AS CHARACTER.

DEFINE VARIABLE fi    AS FileInfo.

vFile = ".\testload.xml".

MESSAGE

 "GetFileName: " Path:GetFileName(vFile) SKIP

 "GetExtension: "Path:GetExtension(vFile) SKIP

 "GetFileNameWithoutExtension: " Path:GetFileNameWithoutExtension(vFile) SKIP

 "GetFullPath: " Path:GetFullPath(vFile) SKIP

 "ChangeExtension: " Path:ChangeExtension(vFile,"foo") SKIP

 "GetRandomFileName: " Path:GetRandomFileName() SKIP

 "GetTempFileName: "  Path:GetTempFileName() SKIP

 "GetTempPath: " Path:GetTempPath()

   VIEW-AS ALERT-BOX.

Posted by OctavioOlguin on 24-Sep-2015 12:02

Indeed!!!!

Thanks a lot!!!!

(one side question: where is to get this info? MSDN?)

Posted by Mike Fechner on 24-Sep-2015 12:18

MSDN and Stackoverflow are typically helpful.

Von meinem Windows Phone gesendet

Von: OctavioOlguin
Gesendet: ‎24.‎09.‎2015 19:03
An: TU.OE.Development@community.progress.com
Betreff: RE: [Technical Users - OE Development] A use case for System.IO fileinfo.

Update from Progress Community
OctavioOlguin

Indeed!!!!

Thanks a lot!!!!

(one side question: where is to get this info? MSDN?)

View online

 

You received this notification because you subscribed to the forum.  To unsubscribe from only this thread, go here.

Flag this post as spam/abuse.

Posted by tbergman on 24-Sep-2015 12:20

In general, when I need to figure something out using .Net, I use google and search for what I want to do along with .Net and sometimes C# as keywords. The C# examples are usually pretty easy to translate. Of course MSDN is good reference material but I usually go there only after getting a clue on what I need elsewhere.

I did a presentation on using .Net for things like this at the PugChallenge event in June. The slides and code examples are available here http://pugchallenge.org/downloads2015.html

Posted by OctavioOlguin on 24-Sep-2015 12:56

Just wonder,... (And i guess it just slipped in)

the line about:

DEFINE VARIABLE fi    AS FileInfo.

is doing something in the simple code? as I took it out and it worked the same...

Posted by tbergman on 25-Sep-2015 12:13

This line was inadvertently left in when I copied what I posted from some code that used it. You don't need it but you might be interested in the .Net fileinfo class as an alternative to Progress's.

This thread is closed