What is wrong with this for loop in my script?











up vote
0
down vote

favorite












K:bin>type get_date_without_space.bat
SET DATE_WITH_SPACE=%DATE%
FOR /F "TOKENS=1-2" %I IN ("%DATE_WITH_SPACE%") DO SET DATE_WITHOUT_SPACE=%I_%J
ECHO %DATE_WITHOUT_SPACE%


This doesn't work. Why?



K:bin>get_date_without_space.bat
K:bin>SET DATE_WITH_SPACE=Fri 11/16/2018
DATE_WITH_SPACEI_J was unexpected at this time.

K:bin>FOR /F "TOKENS=1-2" DATE_WITH_SPACEI_J
K:bin>









share|improve this question









New contributor




Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    To replace your space , simply use string substitution Echo %date: =_%
    – LotPings
    yesterday










  • This works. But can you give me the syntax of the FOR statement, in order to do the job? I still don't find the correct statement.
    – Francky Leyn
    yesterday










  • As I wrote in my first comment, double the percent signs of the for meta variables %%I and %%J See ss64.com/nt/for.html
    – LotPings
    yesterday










  • run for /? and read it's output
    – phuclv
    yesterday















up vote
0
down vote

favorite












K:bin>type get_date_without_space.bat
SET DATE_WITH_SPACE=%DATE%
FOR /F "TOKENS=1-2" %I IN ("%DATE_WITH_SPACE%") DO SET DATE_WITHOUT_SPACE=%I_%J
ECHO %DATE_WITHOUT_SPACE%


This doesn't work. Why?



K:bin>get_date_without_space.bat
K:bin>SET DATE_WITH_SPACE=Fri 11/16/2018
DATE_WITH_SPACEI_J was unexpected at this time.

K:bin>FOR /F "TOKENS=1-2" DATE_WITH_SPACEI_J
K:bin>









share|improve this question









New contributor




Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    To replace your space , simply use string substitution Echo %date: =_%
    – LotPings
    yesterday










  • This works. But can you give me the syntax of the FOR statement, in order to do the job? I still don't find the correct statement.
    – Francky Leyn
    yesterday










  • As I wrote in my first comment, double the percent signs of the for meta variables %%I and %%J See ss64.com/nt/for.html
    – LotPings
    yesterday










  • run for /? and read it's output
    – phuclv
    yesterday













up vote
0
down vote

favorite









up vote
0
down vote

favorite











K:bin>type get_date_without_space.bat
SET DATE_WITH_SPACE=%DATE%
FOR /F "TOKENS=1-2" %I IN ("%DATE_WITH_SPACE%") DO SET DATE_WITHOUT_SPACE=%I_%J
ECHO %DATE_WITHOUT_SPACE%


This doesn't work. Why?



K:bin>get_date_without_space.bat
K:bin>SET DATE_WITH_SPACE=Fri 11/16/2018
DATE_WITH_SPACEI_J was unexpected at this time.

K:bin>FOR /F "TOKENS=1-2" DATE_WITH_SPACEI_J
K:bin>









share|improve this question









New contributor




Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











K:bin>type get_date_without_space.bat
SET DATE_WITH_SPACE=%DATE%
FOR /F "TOKENS=1-2" %I IN ("%DATE_WITH_SPACE%") DO SET DATE_WITHOUT_SPACE=%I_%J
ECHO %DATE_WITHOUT_SPACE%


This doesn't work. Why?



K:bin>get_date_without_space.bat
K:bin>SET DATE_WITH_SPACE=Fri 11/16/2018
DATE_WITH_SPACEI_J was unexpected at this time.

K:bin>FOR /F "TOKENS=1-2" DATE_WITH_SPACEI_J
K:bin>






windows-10 batch






share|improve this question









New contributor




Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 18 hours ago









JakeGould

30.5k1093134




30.5k1093134






New contributor




Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked yesterday









Francky Leyn

223




223




New contributor




Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 1




    To replace your space , simply use string substitution Echo %date: =_%
    – LotPings
    yesterday










  • This works. But can you give me the syntax of the FOR statement, in order to do the job? I still don't find the correct statement.
    – Francky Leyn
    yesterday










  • As I wrote in my first comment, double the percent signs of the for meta variables %%I and %%J See ss64.com/nt/for.html
    – LotPings
    yesterday










  • run for /? and read it's output
    – phuclv
    yesterday














  • 1




    To replace your space , simply use string substitution Echo %date: =_%
    – LotPings
    yesterday










  • This works. But can you give me the syntax of the FOR statement, in order to do the job? I still don't find the correct statement.
    – Francky Leyn
    yesterday










  • As I wrote in my first comment, double the percent signs of the for meta variables %%I and %%J See ss64.com/nt/for.html
    – LotPings
    yesterday










  • run for /? and read it's output
    – phuclv
    yesterday








1




1




To replace your space , simply use string substitution Echo %date: =_%
– LotPings
yesterday




To replace your space , simply use string substitution Echo %date: =_%
– LotPings
yesterday












This works. But can you give me the syntax of the FOR statement, in order to do the job? I still don't find the correct statement.
– Francky Leyn
yesterday




This works. But can you give me the syntax of the FOR statement, in order to do the job? I still don't find the correct statement.
– Francky Leyn
yesterday












As I wrote in my first comment, double the percent signs of the for meta variables %%I and %%J See ss64.com/nt/for.html
– LotPings
yesterday




As I wrote in my first comment, double the percent signs of the for meta variables %%I and %%J See ss64.com/nt/for.html
– LotPings
yesterday












run for /? and read it's output
– phuclv
yesterday




run for /? and read it's output
– phuclv
yesterday










1 Answer
1






active

oldest

votes

















up vote
0
down vote













FOR /F "TOKENS=1-2" %%I IN ("%DATE_WITH_SPACE%") DO SET DATE_WITHOUT_SPACE=%%I_%%J


The meta variables are I and J and the original code used %I and %J instead of %%I and %%J.






share|improve this answer










New contributor




Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















  • If you need to post additional information to your question, please edit it to do so. But posting this as an answer? Nope.
    – JakeGould
    yesterday










  • This is not additional information to be added to the question;  this is the answer (albeit woefully terse).
    – Scott
    yesterday










  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
    – Ramhound
    yesterday






  • 1




    @JakeGould: The problem was that the OP was using %I and %J in a BAT file.  The answer (shown above) is to use %%I and %%J instead of %I and %J. (I did say that it was woefully terse.)
    – Scott
    21 hours ago








  • 1




    @Scott Makes sense. Edited to add that bit of info.
    – JakeGould
    18 hours ago











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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',
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
});


}
});






Francky Leyn is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1376063%2fwhat-is-wrong-with-this-for-loop-in-my-script%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








up vote
0
down vote













FOR /F "TOKENS=1-2" %%I IN ("%DATE_WITH_SPACE%") DO SET DATE_WITHOUT_SPACE=%%I_%%J


The meta variables are I and J and the original code used %I and %J instead of %%I and %%J.






share|improve this answer










New contributor




Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















  • If you need to post additional information to your question, please edit it to do so. But posting this as an answer? Nope.
    – JakeGould
    yesterday










  • This is not additional information to be added to the question;  this is the answer (albeit woefully terse).
    – Scott
    yesterday










  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
    – Ramhound
    yesterday






  • 1




    @JakeGould: The problem was that the OP was using %I and %J in a BAT file.  The answer (shown above) is to use %%I and %%J instead of %I and %J. (I did say that it was woefully terse.)
    – Scott
    21 hours ago








  • 1




    @Scott Makes sense. Edited to add that bit of info.
    – JakeGould
    18 hours ago















up vote
0
down vote













FOR /F "TOKENS=1-2" %%I IN ("%DATE_WITH_SPACE%") DO SET DATE_WITHOUT_SPACE=%%I_%%J


The meta variables are I and J and the original code used %I and %J instead of %%I and %%J.






share|improve this answer










New contributor




Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















  • If you need to post additional information to your question, please edit it to do so. But posting this as an answer? Nope.
    – JakeGould
    yesterday










  • This is not additional information to be added to the question;  this is the answer (albeit woefully terse).
    – Scott
    yesterday










  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
    – Ramhound
    yesterday






  • 1




    @JakeGould: The problem was that the OP was using %I and %J in a BAT file.  The answer (shown above) is to use %%I and %%J instead of %I and %J. (I did say that it was woefully terse.)
    – Scott
    21 hours ago








  • 1




    @Scott Makes sense. Edited to add that bit of info.
    – JakeGould
    18 hours ago













up vote
0
down vote










up vote
0
down vote









FOR /F "TOKENS=1-2" %%I IN ("%DATE_WITH_SPACE%") DO SET DATE_WITHOUT_SPACE=%%I_%%J


The meta variables are I and J and the original code used %I and %J instead of %%I and %%J.






share|improve this answer










New contributor




Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









FOR /F "TOKENS=1-2" %%I IN ("%DATE_WITH_SPACE%") DO SET DATE_WITHOUT_SPACE=%%I_%%J


The meta variables are I and J and the original code used %I and %J instead of %%I and %%J.







share|improve this answer










New contributor




Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this answer



share|improve this answer








edited 18 hours ago









JakeGould

30.5k1093134




30.5k1093134






New contributor




Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









answered yesterday









Francky Leyn

223




223




New contributor




Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • If you need to post additional information to your question, please edit it to do so. But posting this as an answer? Nope.
    – JakeGould
    yesterday










  • This is not additional information to be added to the question;  this is the answer (albeit woefully terse).
    – Scott
    yesterday










  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
    – Ramhound
    yesterday






  • 1




    @JakeGould: The problem was that the OP was using %I and %J in a BAT file.  The answer (shown above) is to use %%I and %%J instead of %I and %J. (I did say that it was woefully terse.)
    – Scott
    21 hours ago








  • 1




    @Scott Makes sense. Edited to add that bit of info.
    – JakeGould
    18 hours ago


















  • If you need to post additional information to your question, please edit it to do so. But posting this as an answer? Nope.
    – JakeGould
    yesterday










  • This is not additional information to be added to the question;  this is the answer (albeit woefully terse).
    – Scott
    yesterday










  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
    – Ramhound
    yesterday






  • 1




    @JakeGould: The problem was that the OP was using %I and %J in a BAT file.  The answer (shown above) is to use %%I and %%J instead of %I and %J. (I did say that it was woefully terse.)
    – Scott
    21 hours ago








  • 1




    @Scott Makes sense. Edited to add that bit of info.
    – JakeGould
    18 hours ago
















If you need to post additional information to your question, please edit it to do so. But posting this as an answer? Nope.
– JakeGould
yesterday




If you need to post additional information to your question, please edit it to do so. But posting this as an answer? Nope.
– JakeGould
yesterday












This is not additional information to be added to the question;  this is the answer (albeit woefully terse).
– Scott
yesterday




This is not additional information to be added to the question;  this is the answer (albeit woefully terse).
– Scott
yesterday












If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
– Ramhound
yesterday




If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
– Ramhound
yesterday




1




1




@JakeGould: The problem was that the OP was using %I and %J in a BAT file.  The answer (shown above) is to use %%I and %%J instead of %I and %J. (I did say that it was woefully terse.)
– Scott
21 hours ago






@JakeGould: The problem was that the OP was using %I and %J in a BAT file.  The answer (shown above) is to use %%I and %%J instead of %I and %J. (I did say that it was woefully terse.)
– Scott
21 hours ago






1




1




@Scott Makes sense. Edited to add that bit of info.
– JakeGould
18 hours ago




@Scott Makes sense. Edited to add that bit of info.
– JakeGould
18 hours ago










Francky Leyn is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















Francky Leyn is a new contributor. Be nice, and check out our Code of Conduct.













Francky Leyn is a new contributor. Be nice, and check out our Code of Conduct.












Francky Leyn is a new contributor. Be nice, and check out our Code of Conduct.















 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1376063%2fwhat-is-wrong-with-this-for-loop-in-my-script%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Paul Cézanne

UIScrollView CustomStickyHeader Resize height generates problems when scroll is too fast

Angular material date-picker (MatDatepicker) auto completes the date on focus out