Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How to? How to use *just* the current folder name in a variable

Feb
5
0
I am in a subfolder. Oh, let's call it: \\mycomputer\c\myfolder\mysubfolder.

I want to grab just the subfolder name to set as a variable. In other words, the stuff to the right of the rightmost backslash.

%_CWD comes close, but I don't want the full directory structure, just "mysubfolder".

Advice on how to do that? Split off the directory structure, just return the folder name?

Thanks.
 
I am in a subfolder. Oh, let's call it: \\mycomputer\c\myfolder\mysubfolder.

I want to grab just the subfolder name to set as a variable. In other words, the stuff to the right of the rightmost backslash.

%_CWD comes close, but I don't want the full directory structure, just "mysubfolder".

Advice on how to do that? Split off the directory structure, just return the folder name?

Thanks.
You can use the @WORD function. You'll need to specify the backslash as the separator, and if you use an index of "-0" it will return the rightmost word, like this:

Code:
x:\path\to\this\folder>echo %_cwd
X:\path\to\this\folder

x:\path\to\this\folder>echo %@word["\",-0,%_cwd]
folder
 
As long as your directory name doesn't end in a backslash, you can also use the @FILENAME function:

Code:
C:\Bin\JPSDK\ipcfg>echo %_cwd
C:\Bin\JPSDK\ipcfg

C:\Bin\JPSDK\ipcfg>echo %@filename[%_cwd]
ipcfg

C:\Bin\JPSDK\ipcfg>
 
You can use the @WORD function. You'll need to specify the backslash as the separator, and if you use an index of "-0" it will return the rightmost word, like this:

Code:
x:\path\to\this\folder>echo %_cwd
X:\path\to\this\folder

x:\path\to\this\folder>echo %@word["\",-0,%_cwd]
folder
Thank you, RogerB. That works!
 
As long as your directory name doesn't end in a backslash, you can also use the @FILENAME function:

Code:
C:\Bin\JPSDK\ipcfg>echo %_cwd
C:\Bin\JPSDK\ipcfg

C:\Bin\JPSDK\ipcfg>echo %@filename[%_cwd]
ipcfg

C:\Bin\JPSDK\ipcfg>
Thank you, Charles. That works too!
 
Back
Top