Reputation: 143
SET jobnumber=%CD:~6,6%
While I am familiar with the CD command, I have never seen this particular syntax before and I can't manage to hunt down the exact purpose. The closest thing that I have found is:
CD /d "%~dp0"
-which merely performs a CD to the location of the batch script file. I can't find anything on the exact syntax that is shown in the first example, however. In the batch file, the variable is later called like so:
SET filepath=C:\info\jobs\%jobnumber%
The job folder contains several dozen subfolders, all of which have a six-digit name. The script was never completed so there is nothing left to go on, leaving me in a state of extreme curiosity. Ideas?
Upvotes: 1
Views: 36
Reputation: 27311
The %CD%
variable contains the current directory.
The other syntax specifies substrings for an expansion.
(from set /?
)
%PATH:~10,5%
would expand the PATH environment variable, and then use only the 5 characters that begin at the 11th (offset 10) character of the expanded result. If the length is not specified, then it defaults to the remainder of the variable value. If either number (offset or length) is negative, then the number used is the length of the environment variable value added to the offset or length specified.
%PATH:~-10%
would extract the last 10 characters of the PATH variable.
%PATH:~0,-2%
would extract all but the last 2 characters of the PATH variable.
Upvotes: 2