This is a Peoplesoft peoplcode question for substring

617 views Asked by At

I have an output for an SQLEXEC "C:\Users\Desktop\XYZ\MMMM.CSV" I need to store this output to a variable in peoplcode which should say &i="C:\Users\Desktop\XYZ". How can I do the substring to remove the file name from the output and get only the location. The location may vary from environment to environment.

Can someone please help me out. Thanks in advance.

2

There are 2 answers

0
Ben Rubin On
&path = "c:\my\path\to\something\file.csv";

&lastIndex = 1;
While True
   &index = Find("\", &path, &lastIndex + 1);
   If &index <> 0 Then
      &lastIndex = &index;
   Else
      Break;
   End-If;
End-While;

If &lastIndex > 1 Then
   &result = Substring(&path, 1, &lastIndex - 1);
   WinMessage(&result);
Else
   WinMessage("invalid path");
End-If;
0
atlasologist On

There are functions in PSXPFUNCLIB.FUNCLIB FieldFormula for dealing with paths, filenames, and extensions. Take a look at GetDirectoryFromPath.