{"id":4444,"date":"2021-11-10T11:35:41","date_gmt":"2021-11-10T11:35:41","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/?post_type=question&#038;p=4444"},"modified":"2021-11-10T11:38:55","modified_gmt":"2021-11-10T11:38:55","slug":"user-prompt-to-set-drive-letter","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/programming\/user-prompt-to-set-drive-letter\/21210.html","title":{"rendered":"User Prompt To Set Drive Letter"},"content":{"rendered":"<p>hi,<\/p>\n<p>i&#8217;m trying to semi-automate a batch file of mine for file backups. i&#8217;m using an &#8216;if&#8217; statement to determine (by comparing to %~d0) if the batch is being run from the backup drive (so use %~d0) or the C: drive (so prompt user for drive letter).<\/p>\n<p>my script seems to work fine from the backup drive, but is &#8216;funny&#8217; if run from the C: drive.<\/p>\n<p>&#8216;funny&#8217; means that i have to input the drive letter three times before the letter is actually &#8216;set&#8217;.<\/p>\n<p>i have added an echo of the resulting drive letter variable, and in each of the first three trys, this is what i get:<\/p>\n<p>1) your drive letter is:<br \/>\n2) your drive letter is: :<br \/>\n3) your drive letter is: i:<br \/>\n+) your drive letter is: i:<\/p>\n<p>the other quirk is that, if i comment out the if statement, and have JUST the user prompt, the variable is set fine.<\/p>\n<p>here is the script:<\/p>\n<p>&nbsp;<\/p>\n<pre>::determine if program is run from local or other drive\r\nIF %~d0==C^: (\r\n\tECHO.\r\n\tECHO ============================\r\n\tECHO START\r\n\tECHO.\r\n\tECHO Please attach the backup drive.\r\n\tECHO.\r\n\t:: set drive letter manually\r\n\tSET \/P L=\"Type the drive letter, then press ENTER: \"\r\n\t:: the caret character is used before special symbols\r\n\tSET D=%L%^:\r\n\tECHO Your drive letter is: %D%\r\n\tPAUSE\r\n\tCLS\r\n) ELSE (\r\n\t::set drive letter of batch file automatically\r\n\tSET D=%~d0\r\n)\r\n<\/pre>\n<p>this is my first ever batch script, but this quirk has got me stumped. has anyone experienced this before? can anyone see where i&#8217;ve gone wrong?<\/p>\n<p>thanks in advance,<br \/>\nagnieszka.<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"iawp_total_views":4},"question-category":[55],"question_tags":[],"class_list":["post-4444","question","type-question","status-publish","hentry","question-category-programming"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question\/4444","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question"}],"about":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/comments?post=4444"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=4444"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=4444"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=4444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}