{"id":91,"date":"2020-02-18T12:47:20","date_gmt":"2020-02-18T10:47:20","guid":{"rendered":"https:\/\/amsd.go.ro\/wordpress\/?p=91"},"modified":"2021-09-07T11:24:43","modified_gmt":"2021-09-07T08:24:43","slug":"automatically-passed-parameters-into-a-windows-batch-file","status":"publish","type":"post","link":"https:\/\/amsd.go.ro\/wordpress\/?p=91","title":{"rendered":"Automatically passed parameters into a Windows batch file"},"content":{"rendered":"<p>The following table outlines how you can modify the passed parameter.<\/p>\n<table border=\"1\">\n<caption>&nbsp;<\/caption>\n<tbody>\n<tr>\n<td style=\"width: 119px;\"><strong>Parameter<\/strong><\/td>\n<td style=\"width: 481px;\"><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 119px;\">%1<\/td>\n<td style=\"width: 481px;\">The normal parameter.<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 119px;\">%~f1<\/td>\n<td style=\"width: 481px;\">Expands %1 to a fully qualified pathname. If you passed only a filename from the current directory, this parameter would also expand to the drive or directory.<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 119px;\">%~d1<\/td>\n<td style=\"width: 481px;\">Extracts the drive letter from %1.<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 119px;\">%~p1<\/td>\n<td style=\"width: 481px;\">Extracts the path from %1.<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 119px;\">%~n1<\/td>\n<td style=\"width: 481px;\">Extracts the filename from %1, without the extension.<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 119px;\">%~x1<\/td>\n<td style=\"width: 481px;\">Extracts the file extension from %1.<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 119px;\">%~s1<\/td>\n<td style=\"width: 481px;\">Changes the <em>n<\/em> and <em>x<\/em> options&rsquo; meanings to reference the short name. You would therefore use %~sn1 for the short filename and %~sx1 for the short extension.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The following table shows how you can combine some of the parameters.<\/p>\n<table border=\"1\">\n<tbody>\n<tr>\n<td style=\"width: 118px;\"><strong>Parameter<\/strong><\/td>\n<td style=\"width: 482px;\"><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 118px;\">%~dp1<\/td>\n<td style=\"width: 482px;\">Expands %1 to a drive letter and path only.<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 119px;\">%~sp1<\/td>\n<td style=\"width: 481px;\">For short path.<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 118px;\">%~nx1<\/td>\n<td style=\"width: 482px;\">Expands %1 to a filename and extension only.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>To see all the parameters in action, put them into the batch file testing.bat, as follows.<\/p>\n<p>@echo off<br \/> echo fully qualified name %~f1<br \/> echo drive %~d1<br \/> echo path %~p1<br \/> echo filename %~n1<br \/> echo file extension %~x1<br \/> echo short filename %~sn1<br \/> echo short file extension %~sx1<br \/> echo drive and directory %~dp1<br \/> echo filename and extension %~nx1<\/p>\n<p>Then, run the file with a long filename. For example, the batch file run on the file c:\\temp\\longfilename.long would produce the following output.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The following table outlines how you can modify the passed parameter. &nbsp; Parameter Description %1 The normal parameter. %~f1 Expands %1 to a fully qualified pathname. If you passed only a filename from the current directory, this parameter would also [&hellip;]<\/p>\n<div class=\"link-more\"><a href=\"https:\/\/amsd.go.ro\/wordpress\/?p=91#more-91\" class=\"more-link\">Continue reading &#10142; <span class=\"screen-reader-text\">Automatically passed parameters into a Windows batch file<\/span><\/a><\/div>","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[17,8,10,12],"class_list":["post-91","post","type-post","status-publish","format-standard","hentry","category-technology","tag-ps_33","tag-ps_20","tag-ps_32","tag-ps_17"],"_links":{"self":[{"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/91","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=91"}],"version-history":[{"count":1,"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/91\/revisions"}],"predecessor-version":[{"id":153,"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/91\/revisions\/153"}],"wp:attachment":[{"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=91"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=91"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=91"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}