Solved

DOS variable set to current directory ONLY.  Not the entire path.

Posted on 2009-07-08
7
545 Views
Last Modified: 2012-06-27
This returns the current directory, but with the entire path as well. How can I get JUST the current directory?

Say this is the path: C:\WINDOWS\system32\2008-02-29_1157 I'm working in.

"set currentdir=%cd%" would set the currentdir variable to "C:\WINDOWS\system32\2008-02-29_1157"  (if run from inside that directory, of course)

That's handy, but how would I set a variable to the actual current directory ONLY.  I need the variable set to: "2008-02-29_1157" only.

The reason for this is that I need to use tokens of that variable to rename files located in that directory.

0
Comment
Question by:americannb
  • 3
  • 2
  • 2
7 Comments
 
LVL 68

Accepted Solution

by:
Qlemo earned 65 total points
ID: 24806932
In a batch file:
for %%D in ("%cd%") do set currentdir=%%~nD
0
 
LVL 16

Assisted Solution

by:t0t0
t0t0 earned 60 total points
ID: 24807036
Yep, as Qlemo has shown, you have to 'cheat' dos into returning what is believes is a filename. In fact, because foldernames can also contain a dotted 'extension name' it is better to use the following:

   for /f "tokens=*" %%a in ('cd') do set currentdir=%%~nxa

or

   for %%a in ("%cd%") do set currentdir=%%~nxa
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 24807069
Confirmed.
0
Do email signature updates give you a headache?

Do you feel like you are constantly making changes to email signatures? Are the images not formatting how you want them to? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today.

 
LVL 16

Expert Comment

by:t0t0
ID: 24807102
:-)
0
 

Author Closing Comment

by:americannb
ID: 31601264
All excellent answers and very helpful!
0
 

Author Comment

by:americannb
ID: 24807129
BAM!  That's the stuff, fellas!  I can actually use both answers in different situations!  And the different answers also helped me understand the logic which I can apply other places.  Thanks a bunch!!!


0
 
LVL 16

Expert Comment

by:t0t0
ID: 24807169
WOW! That was quick! Thank you, and glad we could help in other ways too.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to do advance search in Windows 2008? 11 38
deploy workstation 4 80
mac maintenance 6 34
i am cortana ask me anything 5 27
NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now