Finding the base file name - progress-4gl

What the easiest way to find the base filename in progress.
I have:
/tmp/admin/run/test.txt
and I want:
test.txt
10.2b

Use the R-INDEX() function to find the right-most "/".
define variable path as character no-undo initial "/tmp/admin/run/test.txt".
display
path format "x(60)" skip
substring( path, r-index( path, "/" ) + 1 ) format "x(60)"
.

Related

How to replace a string by a subtring in postgres?

I have the following file name in a column on my db: /folder/path/24/24_1543250974365.wav
And I want to replace it by: 24_1543250974365.wav
In summary, I need to cut off the path and replace it by what comes after the last "/" in the String.
My idea is to find the last occurrence of "/" and get the string from there to the end and do a replacement, but not sure if that's the best way to do that
UPDATE tablename
SET file = REPLACE(file, file, substring('/', 1))
WHERE id=1;
I'll need a function that replace all data in this column, so I don't have anymore the entire path but only the file name. Any help would be appreciated!
You might have to add or subtract 1, but this should work
right(file,strpos(reverse(file),'/'))
select right(file,position('/' in reverse(file))-1)

Modelica combiTimeTable

I have a few questions regarding combitimeTables: I tired to import a txt file (3 columns: first time + 2 measured data)into a combitimeTable. - Does the txt file have to have the following header #1; double K(x,y) - Is it right, that the table name in combitimeTable have to have the same name than the variable after double (in my case K)? - I get errors if i try to connect 2 outputs of the table (column 1 and column2). Do I have to specify how many columns that I want to import?
And: Why do i have to use in the path "/" instead of "\" ?
Modelica Code:
Modelica.Blocks.Sources.CombiTimeTable combiTimeTable(
tableOnFile=true,
tableName="K",
fileName="D:/test.txt")
Thank you very much!
The standard text file format for CombiTables is:
#1
double K(4,3)
0 1 10
1 3 20
2 5 30
3 7 40
In this case note the "tableName" parameter I would set as a modifier to the CombiTable (or CombiTimeTable) is "K". And yes, the numbers in parenthesis indicate the dimensions of the data to the tool, so in this case 4 rows and 3 columns.
Regarding the path separator "/" or "\", the backslash character "\" which is the path separator in Windows where as the forward slash "/" is the path separator on Unix like systems (e.g. Linux). The issue is that in most libraries the backslash is used as an escape character. So for example "\n" indicates new line and "\t" indicates tab so if my file name string was "D:\nextfolder\table.txt", this would actually look something like:
D:
extfolder able.txt
Depending on your Modelica simulation tool however it might correct this. So if you used a file selection dialog box to choose your file, the tool should automatically switch the file separator character to the forward slash "/" and your text would look like:
combiTimeTable(
tableOnFile=true,
tableName="K",
fileName="D:/nextfolder/table.txt",
columns=2:3)
If you are getting errors in your connect statement, I would guess you might have forgotten the "columns" parameter. The default value for this parameter comes from the "table" parameter (which is empty by default because there are zero rows by two columns), not from the data in the file. So when you are reading data from a file you need to explicitly set this

check file existance in progress 4GL

How to check existance of particular file by use of code.
Eg.
def var a as character.
a = "abc.p"
run value(a).
---> here first i want to check if abc.p exist in workspace or not.
You can use the SEARCH function. Directly from the online manual:
SEARCH function
Searches the directories and libraries defined in the PROPATH environment variable for a file. The SEARCH function returns the full pathname of the file unless it is found in your current working directory. If SEARCH does not find the file, it returns the Unknown value (?).
Syntax
SEARCH ( opsys-file )
opsys-file
A character expression whose value is the name of the file you want to find. The name can include a complete or partial directory path. If opsys-file is a constant string, you must enclose it in quotation marks (" "). The value of opsys-file must be no more than 255 characters long.
Example:
DEFINE VARIABLE cPgm AS CHARACTER NO-UNDO.
cPgm = "test.p".
IF SEARCH(cPgm) <> ? THEN
RUN VALUE(cPgm).
If you provide a fully qualified pathname, SEARCH checks if the file exists. In this case, SEARCH does not search directories on the PROPATH.
If you do not want to use the propath you can use the FILE-INFO system handle.
After setting FILE-NAME, you can check the FILE-TYPE if it exists. See also the Progress Help for FILE-INFO.
FILE-INFO:FILE-NAME = a.
IF FILE-INFO:FILE-TYPE MATCHES "*F*"
THEN RUN VALUE(FILE-INFO:FULL-PATHNAME).

uigetfile not pulling entire file name

I'm using uigetfile to upload my data. I've time stamped my data with a date. So a file I want to upload looks like Data-Dec01_11/45/35.txt The problem is uigetfile reads till the first "/" and then assumes that that is the end of the file name. Thus it pulls the file name Data-Dec01_11. But of course when I load that file it doesn't exist. How do I force uigetfile to pull the entire file name?
You cannot use slashes or backslashes in your file names, as they can be mistaken with the file separator, as in your case.
You can use ´regexpr´ to rename your files so they do not contain illegal characters, as explained in this trhead.
I copy here the code they suggest for your convenience (I've just added a slash and a backslash to the example string so you can see the results):
% these characters are allowed
legalchars = 'a-zA-Z0-9\-\ \_\.' ;
% illegal filename
A = 'Some#charac\ters$are(not&allowed/.txt'
% replace every other character with an underscore
B = regexprep(A,['[^' legalchars ']'],'_')

T-SQL pathname manipulation

OK so I'm a bit rusty on parts of T-SQL such as string manipulation
I got a string in a field called [path] the value of the field could look like
'foo\Branches\Bar\Baz\Helpers\FileNotFoundResult.cs'
I need to update the field (for all records) so that the result will be
'Branches\Bar\Baz\Helpers\FileNotFoundResult.cs'
that is strip of anything before the first '\' and the '\'
so I'd appricate if any one could help me fill in the "blanks"
UPDATE SourceFiles
SET Path = <blanks>
Something like
UPDATE SourceFiles
SET Path = SUBSTRING(Path,CHARINDEX('\',Path)+1,8000)
(Assuming your Path column isn't a varchar(max))
If your path column might not contain a backslash at all, you might want:
UPDATE SourceFiles
SET Path = CASE
WHEN CHARINDEX('\',Path) = 0 THEN Path
ELSE SUBSTRING(Path,CHARINDEX('\',Path)+1,8000)
END