system command accessing folders with spaces
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.
matlab
add a comment |
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.
matlab
Did you examine the contents ofSTR
to see what it looks like? I believesprintf
eats up the backslashes. It would be simpler and safer to conscatenate strings with['cd ',folder]
.
– Cris Luengo
Dec 30 '18 at 19:56
Just for the recordsprintf
only manipulates the format string, e.g.cd %s
, not the input string soSTR
would still have the backslashes. I'm pretty sure the problem with the input to bash (which is a bit surprising since I would have thought the example code would work). The other issue may be that something else in the path is wrong ...
– Jimbo
Dec 31 '18 at 2:58
add a comment |
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.
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.
matlab
matlab
edited Dec 30 '18 at 19:37
Banghua Zhao
1,2771719
1,2771719
asked Dec 30 '18 at 4:27
theotherlittleguytheotherlittleguy
31
31
Did you examine the contents ofSTR
to see what it looks like? I believesprintf
eats up the backslashes. It would be simpler and safer to conscatenate strings with['cd ',folder]
.
– Cris Luengo
Dec 30 '18 at 19:56
Just for the recordsprintf
only manipulates the format string, e.g.cd %s
, not the input string soSTR
would still have the backslashes. I'm pretty sure the problem with the input to bash (which is a bit surprising since I would have thought the example code would work). The other issue may be that something else in the path is wrong ...
– Jimbo
Dec 31 '18 at 2:58
add a comment |
Did you examine the contents ofSTR
to see what it looks like? I believesprintf
eats up the backslashes. It would be simpler and safer to conscatenate strings with['cd ',folder]
.
– Cris Luengo
Dec 30 '18 at 19:56
Just for the recordsprintf
only manipulates the format string, e.g.cd %s
, not the input string soSTR
would still have the backslashes. I'm pretty sure the problem with the input to bash (which is a bit surprising since I would have thought the example code would work). The other issue may be that something else in the path is wrong ...
– Jimbo
Dec 31 '18 at 2:58
Did you examine the contents of
STR
to see what it looks like? I believe sprintf
eats up the backslashes. It would be simpler and safer to conscatenate strings with ['cd ',folder]
.– Cris Luengo
Dec 30 '18 at 19:56
Did you examine the contents of
STR
to see what it looks like? I believe sprintf
eats up the backslashes. It would be simpler and safer to conscatenate strings with ['cd ',folder]
.– Cris Luengo
Dec 30 '18 at 19:56
Just for the record
sprintf
only manipulates the format string, e.g. cd %s
, not the input string so STR
would still have the backslashes. I'm pretty sure the problem with the input to bash (which is a bit surprising since I would have thought the example code would work). The other issue may be that something else in the path is wrong ...– Jimbo
Dec 31 '18 at 2:58
Just for the record
sprintf
only manipulates the format string, e.g. cd %s
, not the input string so STR
would still have the backslashes. I'm pretty sure the problem with the input to bash (which is a bit surprising since I would have thought the example code would work). The other issue may be that something else in the path is wrong ...– Jimbo
Dec 31 '18 at 2:58
add a comment |
1 Answer
1
active
oldest
votes
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)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53975282%2fsystem-command-accessing-folders-with-spaces%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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)
add a comment |
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)
add a comment |
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)
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)
edited Dec 31 '18 at 2:59
answered Dec 31 '18 at 2:52
JimboJimbo
7891617
7891617
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53975282%2fsystem-command-accessing-folders-with-spaces%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Did you examine the contents of
STR
to see what it looks like? I believesprintf
eats up the backslashes. It would be simpler and safer to conscatenate strings with['cd ',folder]
.– Cris Luengo
Dec 30 '18 at 19:56
Just for the record
sprintf
only manipulates the format string, e.g.cd %s
, not the input string soSTR
would still have the backslashes. I'm pretty sure the problem with the input to bash (which is a bit surprising since I would have thought the example code would work). The other issue may be that something else in the path is wrong ...– Jimbo
Dec 31 '18 at 2:58