rgrant1993 Posted August 21, 2011 Share Posted August 21, 2011 Basically i have multi files to run creating a program.all of the files are in the same folder, so i need my .batch file to retrieve its own location to open the files in a sequencing order.using the directory input information (C:\Users\Richard\Desktop\Folder) is out of the question because whome ever downloads the file may move the folder to a different location.This WOULD be much appreciated! Link to comment Share on other sites More sharing options...
gunsmokingman Posted August 21, 2011 Share Posted August 21, 2011 How to get Current Location@Echo OffCLSMode 62,9Color F9Echo.Echo %CD%pause Link to comment Share on other sites More sharing options...
allen2 Posted August 21, 2011 Share Posted August 21, 2011 (edited) Hum %CD% will only get the location of the folder from where the batch is launched => if your batch is in e:\temp and then launched from C:\ %CD% will be C:\. It also won't work with unc path.The right variable there is %~dp0.To properly use it, something like this should be used at the beginning of your batch: set batchfolder=%~dp0echo %batchfolder% Edited August 21, 2011 by allen2 Link to comment Share on other sites More sharing options...
jaclaz Posted August 21, 2011 Share Posted August 21, 2011 (edited) The right variable there is %~dp0.To be picky, the variable is %0 and %~dp0 is a possible expansion of it.http://www.robvanderwoude.com/ntfor.phpYou can now use the following optional syntax:%~i - expands %i removing any surrounding quotes (")%~fi - expands %i to a fully qualified path name%~di - expands %i to a drive letter only%~pi - expands %i to a path only%~ni - expands %i to a file name only%~xi - expands %i to a file extension only%~si - expanded path contains short names only%~ai - expands %i to file attributes of file%~ti - expands %i to date/time of file%~zi - expands %i to size of file%~$PATH:i - searches the directories listed in the PATH environment variable and expands %i to the fully qualified name of the first one found.If the environment variable name is not defined or the file is not found by the search, then this modifier expands to the empty stringThe modifiers can be combined to get compound results:%~dpi - expands %i to a drive letter and path only%~nxi - expands %i to a file name and extension only%~fsi - expands %i to a full path name with short names only%~dp$PATH:i - searches the directories listed in the PATH environment variable for %i and expands to the drive letter and path of the first one found.%~ftzai - expands %i to a DIR like output linetry also %~f0@gunsmokingmanthis may interest you:http://www.robvanderwoude.com/ntset.php%CD% expands to the current directory string (no trailing backslash, unless the current directory is a root directory)%__CD__% expands to the current directory string, always terminated with a trailing backslashalso a few new (to me at least dynamic variables):%=C:% expands to the current directory string on the C: drive%=D:% expands to the current directory string on the D: drive if drive D: has been accessed in the current CMD session%=ExitCode% expands to the hexadecimal value of the last return code set by EXIT /B%=ExitCodeAscii% expands to the ASCII value of the last return code set by EXIT /B if greater than 32 (decimal)The %=D:% may answer the question "Has drive D:\ ever been accessed during this CMD session?".I have no idea right now where and why this can be useful, but it is "good to know".jaclaz Edited August 21, 2011 by jaclaz Link to comment Share on other sites More sharing options...
rgrant1993 Posted August 26, 2011 Author Share Posted August 26, 2011 Problem solved x D thanks "Gunsmokingman" x D Link to comment Share on other sites More sharing options...
Guest Posted August 26, 2011 Share Posted August 26, 2011 To be picky, the variable is %0 and %~dp0 is a possible expansion of it.http://www.robvanderwoude.com/ntfor.phpThanks, jaclaz, for the links and explanations. I've always wondered how that syntax worked and had no freaking idea how to look it up and research it. Link to comment Share on other sites More sharing options...
bphlpt Posted August 27, 2011 Share Posted August 27, 2011 Another favorite site that I use, 5eraph, as I know jaclaz does as well, is this one - http://ss64.com/nt/syntax-args.html.Cheers and Regards Link to comment Share on other sites More sharing options...
Guest Posted August 27, 2011 Share Posted August 27, 2011 That's another good site, bphlpt. Somehow I've never seen that page though. Link to comment Share on other sites More sharing options...
bphlpt Posted August 27, 2011 Share Posted August 27, 2011 Follow the links at the top of most of the pages for Syntax - Parameters.Cheers and Regards Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now