system command accessing folders with spaces - matlab

I'm currently trying to write a program that requires I access files on a OneDrive folder that will be shared with multiple computers. Currently, an issue is appearing where the 'system' command is throwing an error when I try and access the OneDrive folder because the full path name has spaces in it.
folder = '/Users/myuser/Desktop/OneDrive\ -\ -\ Company\ Name/foldername-AVL'
STR = sprintf('cd %s',folder);
system(STR)
The error I keep receiving is
/bin/bash: line 0: cd: %s/Users/myuser/Desktop/OneDrive: No such file
or directory
So it is effectively cutting off all entries after the second space. I've looked through the documentation and all, and I can't seem to find a solution or a guide for using the system command in this specific situation.

I am guessing that you are trying to escape the spaces. In general I prefer to wrap all arguments that have spaces with double quotes. I would have guessed that escaping the path would work as well, but maybe not ...
This should work ... and it is much easier to read (IMHO).
folder = '"/Users/myuser/Desktop/OneDrive - - Company Name/foldername-AVL"'
STR = sprintf('cd %s',folder);
system(STR)
OR - moving " to sprintf
folder = '/Users/myuser/Desktop/OneDrive - - Company Name/foldername-AVL'
STR = sprintf('cd "%s"',folder);
system(STR)

Related

AHK Run command with directory path containing space

Using AHK script to open up and launch text files (or script files) within notepad++. I recently had to add spaces to my file path which has caused the problems I now experience. It's as if the space in the file path is escaping the command.
e.g.
Run % "notepad++.exe C:\C Docs\SW\AHK\Desktop1.ahk"
Upon running the above line, it will ask in msgbox: "C:\C" doesn't exist. Create it?
This script happens to be the script location itself. So I also tried the following without success (produces same message):
Run % "notepad++.exe " . a_scriptdir . "\" . A_ScriptName
You are passing two arguments to Notepad++ the first one being C:\C and the second one being Docs\SW\AHK\Desktop1.ahk.
To pass them as one argument, do what you'd always do with command line arguments, quote them.
Run, % "notepad++.exe ""C:\C Docs\SW\AHK\Desktop1.ahk"""
Try like this:
Run notepad++.exe "C:\C Docs\SW\AHK\Desktop1.ahk"

Folder name with space issue

How do I handle a folder name containing spaces in Perl? For example C:\Sample Picture\Data.
I wrote this
use File::Glob ':glob';
$indir = "C:\\Sample Picture\\Data\\";
#flist = bsd_glob( $indir.'*');
This is throwing an error
The syntax of the command is incorrect.
The error message The syntax of the command is incorrect comes from the Windows command line, not from Perl
The issue is not to do with File::Glob, but with whatever you are doing with the contents of #flist. It's my guess that you're using backticks or system to rename one or more of the files or directories. This will fail if you use paths that contain spaces without enclosing the complete path in double quotes
If you need any more help then you must show the relevant part of your code

Load file.q from path containing space character

How to load script file from a path containing spaces?
For example, this works:
\l F:/file.q
Below attempts throw an error:
\l F:/Folder with spaces/file.q
\l "F:/Folder with spaces/file.q"
\l hsym `$"F:/Folder with spaces/file.q"
system "l "F:/Folder with spaces/file.q""
Not exactly practical, but if you need to load files with spaces in the path, you can use windows short file names:
So given a script path: F://Folder with spaces/file with spaces.q
Given
Folder with spaces gets shortname folder~1
script with spaces.q gets shortname filewi~.q
You can load the file as follows in q:
q)system "l F://folder~1/filewi~1.q"
Hello from a q script with spaces in file name
You can get the short name of a file/folder by listing the directory in command print with /x flag (eg. dir /x)
As in general with this situation in windows, you're likely better off avoiding spaces in a filepath.
I know this is a very old post, but just had the same issue. Found a solution that works for me:
system "cd c:/your path/with spaces/"
system "l your_script.q"

Xcopy: invalid number of parameters or file not found error

From inside a .bat file, I m issuing this command
xcopy\s Folder1\folder2\folder3\blah-blah Folder1\temp\folder2\folder3
But I get the error:
The system cannot find the path specified.
I tried copying the same line to command line and tried it:
Then, I get the error, xcopys command not found.
If I try to use xcopy instead of xcopy/s, I get error:
File not found - Folder1folder2folder3blah-blah
If I use xcopy command with backward slash on command line: Invalid number of parameters.
I tried enclosing paths in quotes, but it does not help.
My file names don't have spaces in them but they do have -
I have checked the path of source and destination and they exist
Any help will be appreciated.
Thanks
I guess you're running under windows, so you have to use forward slashes for arguments.
xcopy/s is something very different from xcopy\s. The later searches for an application called s in a subfolder called xcopy. To further avoid confusion, separate the program from its argument(s) with spaces.

Possible issue with international characters in objects and/or paths when copying recursively

I've run into a weird problem after uploading a lot of images with gsutil - the uploaded files cannot be seen via the Google Cloud Console and gsutil itself complains if I try to do a 'gsutil ls '. I am 99% sure it is related to the use of "å" or "Å" together with spaces in the directory name.
All uploads were done recursively from a root folder (large image collection in multiple levels of subdirectories). If I try to upload the files again, gsutil skips them since they are already there, so the upload feature does something - it just isn't working in the same way as the list and download.
An example:
gsutil cp -R -n /Volumes/Photos/digitalfotografen.dk/2009/2009-05-30\ Søgården\ -\ bryllup/ gs://digitalfotografen/2009/
Skipping existing item: gs://digitalfotografen/2009/2009-05-30 Søgården - bryllup/Søgården 0128.CR2
...
OK - so the files are there, but browsing the directory through the Google Cloud Console shows "No results".
Also:
gsutil ls gs://digitalfotografen/2009/2009-06-27 Søgården - reklamefotos/20090627_IMG_0128.CR2
CommandException: "ls" command does not support "file://" URIs. Did you mean to use a gs:// URI?
I tried escaping spaces and used quotation marks in different ways with no luck.
Now, here is the interesting thing:
gsutil cp -R -n /Volumes/Photos/digitalfotografen.dk/2009/2009-05-30\ Søgården\ -\ bryllup/ gs://digitalfotografen/2009/
Copying file:///Volumes/Photos/digitalfotografen.dk/2009/2009-05-30 Søgården - bryllup/Søgården 0128.CR2 [Content-Type=application/octet-stream]...
Here I copied the folder specifically with escaped spaces on the source side, and now the files are uploaded again. This creates a second folder with the same name (at least it appears so in the Cloud Console) and the files are now visible in both folders.
We use three different characters that are outside the standard US ASCII in the Danish character set ("æøå" and the capital "ÆØÅ") but the problem only seems to affect "å" and "Å" - the two others alone or in combination works fine. My hunch is that "å" and "Å" may translate into something entirely different in ASCII that throws things off track when gsutil is allowed to handle the directory naming on its own based on the name of the root folder (doing a multiple level recursion) but works when the user specifies the escaped name of the root folder.
This may be a python issue rather than a gsutil issue, but I am in no way qualified to identify this since I have very close to zero knowledge of programming outside a bit of hodgepodge shell scripts.
We got a trouble with gsutil into ubuntu wsl version windows 10.
The command gsutil work perfectly into the shell but not working when is included into a shell script:
gsutil -m ls -lr gs://project.appspot.com/
Error:
commandexception: "ls" command does not support "file://" urls. did you mean to use a gs:// url?
A workaround cloud be by calling directly the script /usr/lib/google-cloud-sdk/platform/gsutil/gsutil and not calling the link /usr/bin/gsutil:
/usr/lib/google-cloud-sdk/platform/gsutil/gsutil -m ls -lr gs://project.appspot.com/
I don't know why but it's working.
Thank Marion to provide us a such uncommon bug :-)
I know this here is a old error, but nevertheless I had a similar issue as described above.
CommandException: "ls" command does not support "file://" URLs. Did you mean to use a gs:// URL?
Using gsutil from scala code.
import sys.process._
object Main {
def main(args: Array[String]): Unit = {
val clients = s"gsutil ls gs://<bucket name>".!!
val beforeDate: String = "date +%Y-%m-%d -d '-8 days'".!!
val clientList = clients.split("\n").map(f => f.split('/').apply(1)).toList
for (x <- clientList) {
val countImg = (s"gsutil -m ls gs://<bucket name>/$x/${beforeDate.stripLineEnd}" #| "wc -l").!!
println(countImg)
}
}
}
So what I found was that there was a LineEnd character on the beforeDate, when I striped that the error went away. So the error occurs when there is a "special" character in the gs://... path. So be sure to strip variables for any "special" characters.
And all this happened just because I was to lazy to use java.time.LocalDate to generate the beforeDate variable. Hope this here will help others that encounter the same error.