

InterviewSolution
Saved Bookmarks
1. |
Solve : Storing current directory into a variable? |
Answer» <html><body><p>I'm <a href="https://interviewquestions.tuteehub.com/tag/working-243555" style="font-weight:bold;" target="_blank" title="Click to know more about WORKING">WORKING</a> on a concept script that requires me to save the current directory that the script is being run from in a varible to be used later:<br/><br/>Example<br/><br/>set variable = currdir<br/>...<br/>...(somewhere in here it will <a href="https://interviewquestions.tuteehub.com/tag/traverse-1426850" style="font-weight:bold;" target="_blank" title="Click to know more about TRAVERSE">TRAVERSE</a> to another directory)<br/>cp somefile %variable%/required_subdirectoryif you need the current directory then use the CD variable.<br/><br/> Code: <a>[Select]</a>set currentdir=%CD%<br/> grimbear, don't use spaces around the equals sign in batch.<br/>Grimbear<br/>You might like to check the 2 commands<br/>PUSHD<br/>POPD<br/><br/>PUSHD saves the current directory when you can go off an do other processing and POPD will then return you to where you started. Quote from: wbrost on April <a href="https://interviewquestions.tuteehub.com/tag/22-241942" style="font-weight:bold;" target="_blank" title="Click to know more about 22">22</a>, 2010, 08:20:56 AM</p><blockquote>if you need the current directory then use the CD variable.<br/><br/> Code: <a>[Select]</a>set currentdir=%CD%<br/> <br/></blockquote> Why do that when you can just use %CD%? Quote from: Helpmeh on April 23, 2010, 04:18:00 AM<blockquote>Why do that when you can just use %CD%?<br/></blockquote> <br/>because they want to use the current directory at the time they retrieve it later on when it <a href="https://interviewquestions.tuteehub.com/tag/may-557248" style="font-weight:bold;" target="_blank" title="Click to know more about MAY">MAY</a> no longer actually be the current directory?<br/><br/>gpl caught <a href="https://interviewquestions.tuteehub.com/tag/onto-586605" style="font-weight:bold;" target="_blank" title="Click to know more about ONTO">ONTO</a> the possible requirement the OP was after- pushd and popd.</body></html> | |