res.downalod changing the name of .tiff file while downloading if fileName contain forward slash - node.js

I am using express res.download to download the file from the server location as below-
res.download('path', 'report a/b/c.tiff')
on downloading above file name is getting changed to c.tiff.
what will be the possible reason and how to get downloaded file as report a/b/c.tiff only.

/ is a globally user for differentiating directories hence forth OS will not allow / in file names as well as for directory.
In Windows you will get the below error,
likewise linux OS also uses the same. But we can use '\' for creating files. Allowed chars in Linux,
Double your \, like this: \, so that your shell does not interpret the backslashes from your filename as escape characters.
Escape " and ', like this: \", \', so that your shell interprets the double quotes as part of the filename.
Escape $, like this: \$, otherwise your shell will think you're using a variable.
Escape ? and *, like this: \?, *
Hence you download has only c.tff

Related

While passing address in nodejs, when to place '/' between directories and when to place '\\' . And why do we place dot(.) before writing addresses

While passing address in nodejs, when to place '/' between directories and when to place '\' . And why do we place dot(.) before writing addresses
path package provides functionality so that you don't need to worry about what directory separator you need to use.
const path = require('path');
path.join(parentDir, childDir);
And dot represents current directory i.e.
project index file path: /home/user/projects/project-name/index.js
you are in <project-name> folder
so index file path will be ./index.js
In a Unix/Linux environments you place a forward slash as a folder seperator.
e.g. /home/user/image.jpg
In a Windows system you use backslashes as folder seperators, since a backslash is also an escape character in a string you should escape the backslash.
e.g. C:\users\user\image.jpg
You use a . for relative paths.
e.g. if your script runs in /home/user/ and you want to access image.jpg you can do so by ./image.jpg
for more info: https://nodejs.org/api/path.html

How to save python file in jupyter note if path contains spaces %20

When I try to save a file in a jupyter notebook I get an error saying there is no file or directory.
Error Message ___________________________________________________________
Unexpected error while saving file: OneDrive%%20-%%20Files/Desktop/PythonProjects/bhp.ipynb [Errno 2] No such file or directory: 'C:\Users\username\OneDrive%%20-%%20Files\Desktop\PythonProjects\bhp.ipynb'
I began having this problem after a software update where now I can only save things to "OneDrive - Files". Unfortunately, the path to OneDrive contains several spaces - causing this error every time I try to save a new file. I would use a different directory if I could. I was hoping for an easy fix like wrapping the path in quotes - but so far this didn't work.
Replacing the %20 characters with a literal space resolved the issue. I suppose the Jupyter Notebook treats the path the same way as a url and inserts %20 characters for spaces. But when saving to a directory on a pc - the %20 characters can be replaced with a space - without the need to wrap the path in quotations or to place backslashes before the spaces.

Argument escaping not interpreted correctly when running node.js script from Windows PowerShell

Given the following script:
const yargs = require('yargs');
const argv =
yargs
.usage('Usage: $0 [--whatIf]')
.alias('d', 'directory')
.alias('wi', 'whatIf')
.nargs('d', 1)
.describe('d', 'alphabetize this directory')
.describe('whatIf', 'show what would happen if run')
.demandOption(['d'])
.argv;
console.log(argv.directory);
If I invoke the script from Windows PowerShell like so: node .\alphabetizer.js -d 'l:\my folder\Files - Some Files In Here\' --whatIf I get the output l:\my folder\Files - Some Files In Here\" --whatIf where I would expect just l:\my folder\Files - Some Files In Here\. It works OK with folder names that require no escaping, but it seems to get confused by the escaping.
If I examine process.argv, I can see the same escaping issue.
I have noticed that if I remove the trailing slash it will work. However, this still points to the node script not handling the input properly, because this should not be necessary with string set off by single quotes.
Is there a way to make this work?
Both Windows PowerShell (powershell.exe) and PowerShell [Core] v6+ (pwsh) are fundamentally broken with respect to quoting arguments for external programs properly - see this answer for background info.
Generally, PowerShell on Windows has to perform re-quoting behind the scenes in order to ensure that just "..."-quoting is used, given that external programs can't be assumed to understand '...'-quoting too when parsing their command line (which on Windows every program has to do itself).
Windows PowerShell is more broken with respect to arguments that end in \ and have embedded spaces, re-quoting them improperly; e.g.:
PS> foo.exe 'c:\foo \' bar
is translated into the following command line behind the scenes:
foo.exe "c:\ foo \" bar
This is broken, in that most applications - including PowerShell's own CLI - sensibly assume that the \" is an escaped " char. to be taken verbatim, thinking that the argument continues with  bar and then implicitly ends, despite the formal lack of a closing ".
PowerShell [Core] v6+ more sensibly translates the above to foo.exe "c:\foo \\" bar, where the \\ is interpreted as an escaped \, and the following " again has syntactic function.
If you're stuck with Windows PowerShell, your only choices are:
either: if possible, leave off the trailing \
otherwise: manually double it (\\), but only do so if the argument also contains spaces (otherwise, the \\ will be retained as-is, though in the case of filesystem paths that is usually benign).

How do I create files with special characters in Linux?

I am using the touch command to try and create a file with the name "\?$*'KwaMe'*$?\" (quotation marks included as part of the file name). However when I type touch "\?$*'KwaMe'*$?\" in the Terminal, it doesn't give me the result I am expecting. How can I create this file?
You need to escape special characters with the backslash symbol (\).
This command will create a file named "\?$*'KwaMe'*$?\":
touch \"\\\?\$\*\'KwaMe\'\*\$\?\\\"
Explanation
Double your \, like this: \\, so that your shell does not interpret the backslashes from your filename as escape characters.
Escape " and ', like this: \", \', so that your shell interprets the double quotes as part of the filename.
Escape $, like this: \$, otherwise your shell will think you're using a variable.
Escape ? and *, like this: \?, \*, to prevent filename expansion.

How to avoid trailing space being replaced with %20 when downloading a file with WinSACP

I use WinSCP script to download a file from an SFTP site. The file has length of trailing space after the file name.
After it is downloaded to local computer %20 is appended to the file name. For example, file.txt_________ becomes file.txt________%20 on local computer (_ stands for space).
Could you know any command I can put on the WinSCP script to remove it. Thank you in advance.
Add -rawtransfersettings ReplaceInvalidChars=0 to your get command:
get file directory\ -rawtransfersettings ReplaceInvalidChars=0
Read about raw transfer options.
You will lose the trailing spaces though, this way.

Resources