How can I get the file extension - mumps

In MUMPS how can I get the file extension is there a class I can use? Class(%File).GetFilename that will return the Full Message name but i would just like the extension?
Set tNameIn=##class(%File).GetFilename(pRequest.OriginalFilename)

You can use $piece for this.
write $piece(tNameIn, ".", *)
Should return the latest piece delimited my symbol dot
And filename without extension will be
write $piece(tNameIn, ".", 1, *-1)

Related

using a variable to identify file in 'print -dpdf file_name'

I am trying to use a formatted string to identify the file location when using 'print -dpdf file_name' to write a plot (or figure) to a file.
I've tried:
k=1;
file_name = sprintf("\'/home/user/directory to use/file%3.3i.pdf\'",k);
print -dpdf file_name;
but that only gets me a figure written to ~/file_name.pdf which is not what I want. I've tried several other approaches but I cannot find an approach that causes the the third term (file_name, in this example) to be evaluated. I have not found any other printing function that will allow me to perform a formatted write (the '-dpdf' option) of a plot (or figure) to a file.
I need the single quotes because the path name to the location where I want to write the file contains spaces. (I'm working on a Linux box running Fedora 24 updated daily.)
If I compute the file name using the line above, then cut and paste it into the print statement, everything works exactly as I wish it to. I've tried using
k=1;
file_name = sprintf("\'/home/user/directory to use/file%3.3i.pdf\'",k);
print ("-dpdf", '/home/user/directory to use/file001.pdf');
But simply switching to a different form of print statement doesn't solve the problem,although now I get an error message:
GPL Ghostscript 9.16: **** Could not open the file '/home/user/directory to use/file001.pdf' .
**** Unable to open the initial device, quitting.
warning: broken pipe
if you use foo a b this is the same as foo ("a", "b"). In your case you called print ("-dpdf", "file_name")
k = 1;
file_name = sprintf ("/home/user/directory to use/file%3.3i.pdf", k);
print ("-dpdf", file_name);
Observe:
>> k=1;
>> file_name = sprintf ('/home/tasos/Desktop/a folder with spaces in it/this is file number %3.3i.pdf', k)
file_name = /home/tasos/Desktop/a folder with spaces in it/this is file number 001.pdf
>> plot (1 : 10);
>> print (gcf, file_name, '-dpdf')
Tadaaa!
So yeah, no single quotes needed. The reason single quotes work when you're "typing it by hand" is because you're literally creating the string on the spot with the single quotes.
Having said that, it's generally a good idea when generating absolute paths to use the fullfile command instead. Have a look at it.
Tasos Papastylianou #TasosPapastylianou provided great help. My problem is now solved.

unable to open "file name.txt" in octave using fopen

How can I use the fopen function in octave to open a file whose name is file name.txt. I am using octave installed in windows.
thanks
Use fopen to open the file and get the file id, the "r" stands for read mode.
fid = fopen("name.txt", "r");
Then use fgets to retrieve the file line by line and add it to a string. fgets will return -1 once the file has been completely read.
file_string = "";
while((line = fgets(fid)) != -1)
file_string = strcat(file_string, line);
end
Close the file once your done reading it.
fclose(fid);
There you have it, you should now have a variable file_string which contains the contents of your file as a string. Obviously these utilities are much more versatile than just what I described above, so I'd also encourage you to read the docs at :
https://www.gnu.org/software/octave/doc/interpreter/Opening-and-Closing-Files.html#Opening-and-Closing-Files

How to escape quotes that passed from a JSON file to Jade template?

I have some variables stored in a JSON file which will be injected into my generated HTML later. Those variables would be put in places like:
var str = '#{content.str}';
While in the JSON file the content.str might contain ' in it, and it would cause the JavaScript error after rendering the HTML file.
What should I do to prevent this happening?
Thanks,
It's simple -
"I've done it".replace("'", "\\'")
//output "I\'ve done it"
Using RegEx - replace all
"I've done it haven't you".replace(/'/g, "\\'")
//output "I\'ve done it haven\'t you"

How to add certain search and replace pattern on filenames with specific strings

I have written a function, which does some search and replace on the file which I am editing. But for certain files (with some specific keyterms in the filename), I need to add some specific search and replace which is restricted to these files.
I need to know how to fix the following code:
function! Test()
" basic search and replace for all the files
%s/I'll /I will /ge
" if the filename starts with "blah-" the following additional search and replace needed otherwise not
if match(readfile(expand('%:t')),"^blah-")
%s/could'nt /could not /gec
endif
endfunc
And on calling the function :call Test() all these patterns will be executed. Hence, I do not need to worry about the specific instructions on certain file types.
Can anybody help me fixing this problem?
If there is no match -1 is returned from match(). Also, you probably don't need to call readfile() to check the filename. As such, change
if match(readfile(expand('%:t')),"^blah-")
...to...
if match(expand('%:t'), '^blah-') != -1
...and your blah-files (and only your blah-files) will have the extra substitution executed.

How to access a file name containing URL encoding through the browser?

I created a file name called "%20%20.txt" and uploaded in my webs space.
When I am trying to access above file through URL by typing "http://mysite/%20%20.txt", it is showing an error that the file is not found. I know that "%20" will be decoded as a blank space.
How is it possible to access the file through URL?
The %20 that you use in the URL will be decoded, so you are looking for the file " .txt", but the %20 that you used to create the file is not decoded, so the actual name of the file is "%20%20.txt".
You need to use the URL http://mysite/%2520%2520.txt to access the file "%20%20.txt". The %25 is the encoded form of %.
Use %2520%2520.txt, %25 decodes as the percent-sign %. You can use the table on http://www.asciitable.com/. The number after the percent-sign is a hexadecimal representation of the ASCII value.
If you have a long string, you could also use Javascript's encodeURIComponent function:
prompt("Encoded:", encodeURIComponent("%20%20.txt"))
This could be executed in the Javascript console (Ctrl + Shift + J in Firefox) and displays a dialog containing the escape value.
If your file name really is %20%20.txt, try http://yoursite.com/%2520%2520.txt.
%25 is the percentage encoded.
You need to escape those percent signs:
http://mysite/%2520%2520.txt