Changing the suffix of .pdf causes it not to be opened correctly in windows - file-extension

My dilemma is that there is pdf file named 'P01111-AMFLIBL.pdf' , I want to append '.NOSUFFIX' after .pdf so the result will be like 'P01111-AMFLIBL.pdf.NOSUFFIX'.
I am trying to add by this line of code :
fileName = fileName + ".pdf" + ".NOSUFFIX";
It's working, but the problem is that pdf file is not directly getting opened into my system

On Windows, the extension (i.e. suffix starting at last .) determines the file type (and associated program). If you append another suffix, this appended .NOSUFFIX will become the file extension, and the original .pdf will become just a part of the file name.

Related

Getting corrupted PDF file after reading and rewriting it to a new file

I am exploring PDF file format and trying to edit and manipulate its internal data. the problem is that I noticed I always get corrupted files after making any minor change to a file so I tried a very simple example to just read the pdf data and rewrite it to a new "file.pdf" without making any changes, as follows:
file = open('sample.pdf','r',encoding='ansi').read()
file_ = open('output.pdf','w').write(file)
but again I got a corrupted file (can't be opened using Adode reader) so I tried to open it using Google Chrome and it worked properly but with the font has changed to the default instead of the original font file.
I opened the input and output files and compared them using notebad++ and two files matched exactly!
I also opened the output file and copied its content and pasted it to the input file and surprisingly, it worked well, exactly as the input file.
Any ideas what is the problem?

Matlab FTP download files with certain string in name

I am trying to download only certain files from a folder. The folder contains thousands of files named:
z_cams_c_ecmf_20160904000000_prod_fc_sfc_120_duaod550.nc
z_cams_c_ecmf_20160904000000_prod_fc_sfc_120_gtco3.grib
z_cams_c_ecmf_20160904000000_prod_fc_sfc_000_aod550.nc
etc.etc.
I only want those that end in duaod550.nc and aod550.nc
Is there a way to isolate this string from the filename? Unfortunately I cannot use the .nc because there are other files that have this extention and I don't need them.
Looks like what you need to do is use the a wildcard in the ftp command in matlab. From the help
mget(ftpobj,contents) retrieves the file or folder specified by contents from an FTP server into the MATLABĀ® current folder.
contents --
Character vector enclosed in single quotation marks that specifies either a file name or a folder name. Can include a wildcard character (*).
filelist=mget(ftpobj, '*duaod550*')
filelist=mget(ftpobj, '*aod550*')

How to find the file path of a file in livecode

So, I'm incredibly new to LiveCode and I have an external file in the same directory as the .livecode file called 'words.txt', with english words, each on a new line. I plan to read this file into a variable and then pick a random word from that variable. However, I am stumped as to how I must find the file path and insert this into the syntax required for me to do this. My code is as follows:
put url ("binfile:" & filePathGoesHere) into dictionary
replace crlf with lf in dictionary
replace numToChar(13) with lf in dictionary
put any line of dictionary into randomword
The file path is supposed to be inserted into the code at filePathGoesHere. Once the program is compiled I will be moving it and its resources around a bit (from computer to computer), so, beyond the text file staying in the same folder as the compiled program, the file path will change. What extra code would I need to add to make this work, if the folder the compiled program and the txt file is in is called "MyProgram"?
Help is much appreciated, and if further specification is required I can provide it. I also have a folder called "resources" if moving it there can help.
If the stack you're building is for your own use, you can place external files anywhere, but if you're going to deliver your stack to other users, you need plan where you external files are going to be placed, and how.
An easy way to determine the path to a file that sits immediately outside your stack is using the stack's filename:
put the fileName of this stack into theFilePath
set the itemDel to "/"
put "words.txt" into the last item of theFilePath
Now theFilePath variable will an absolute path reference to your external file. If the file is placed inside a folder "TextFiles" you can do this:
put the fileName of this stack into theFilePath
set the itemDel to "/"
put "TextFiles/words.txt" into the last item of theFilePath
If you're going to deliver your stack to other people, you should write your external file/s into a common system folder, or you need to use an installer to define where your files/folders will be placed. Common folder paths are found using the specialFolderPath function:
put specialFolderPath("Documents") into the theFolderPath
A somewhat recent addition to LiveCode is a "Resources" folder -- specialFolderPath("Resources") -- which can be handy for delivering on desktop and mobile platforms. Also, keep in mind that few of these folders allow writing to existing files contained in them for security reasons. "Preferences" and "Documents" are two examples of folders where you can change the contents of files.
The LC dictionary contains details of each of the folders.
If you use the file: scheme instead of bindle: LiveCode will automatically convert end of line characters to LF, so that step may not be necessary. (Although you might need it if you are reading a text file produced in native Windows encoding on a Mac.) You don't even necessarily need to read it into a variable. You could do this:
put any line of URL ("file:" & specialFolderPath("resources") & "/words.txt") \
into tRandomWord

OpenText Hijacks the File Name in Powershell

A user suggested using the OpenText command to import a pipe delimited text file into excel. The problem is, that this seems to hijack the filename and forces it to be a .txt instead of an xlsx. When I try to
-replace ".txt.*", the .txt remains and when I try to force name the file .xlsx, it just makes a "corrupt" xlsx file that won't open properly in excel.
First Question
Finding Powershell names for Excel features
.txt and .xlsx are fundamentally different file types. You can't magically convert one into the other by just renaming the file.
Going out on a limb I guess your problem is that you're trying to save the file, and $excel.ActiveWorkbook.SaveAs($y) (or whatever statement you use) doesn't create an actual workbook.
Try saving it as xlWorkbookDefault:
$excel.ActiveWorkbook.SaveAs($y, 51)

how to add a .remove extension for a zip file

I am trying to send a project file via Gmail and i am having trouble sending the zip file with a .exe file in it. How can i change the zip file to fileName.zip.remove?
You can use the += operator:
string filename = "fileName.zip";
filename += ".remove";
The last line is equivalent to:
filename = filename + ".remove";
A common problem when sending e-mails is that antiviruses reject .exe files, even when they are included in zip files. You can hide the exe file in zip file if you encrypt this file. This involves giving a password to the zip file. You can write down this password in the e-mail text. The antivirus is not smart enough to use it.
I would suggest actually changing the name of the exe file itself and rezipping it and sending it. But to change the name of the file itself, you should be able to right-click on it, and rename should be an option. Just type in .remove, ignore the warning about file extensions if it shows up, and send it! :)

Resources