We help IT Professionals succeed at work.

Prompt for folder name not including the full path

Zoldy2000
Zoldy2000 asked
on
269 Views
Last Modified: 2012-05-08
What I am currently doing is the following.

REM Make VB Script to get a foldername
echo Set objShell = CreateObject^( "Shell.Application" ^) > "%temp%\getpath.vbs"
echo set objFolder = objShell.BrowseForFolder^( 0, "Select Customer", ^&H10^&, "t:\"^)>> "%temp%\getpath.vbs"
echo wscript.echo objFolder.Self.Path >> "%temp%\getpath.vbs"
for /f "tokens=*" %%a in ('cscript //nologo "%temp%\getpath.vbs"') do set folder=%%a
if "%folder%"=="" goto :Eof

What I want to do is modify this so the result does not include the full path....

So If the result is t:\folder\subfolder    

I want to get just subfolder

Thank in advance
Comment
Watch Question

Test your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
no still contains full path

Steve KnightIT Consultancy
CERTIFIED EXPERT

Commented:
That should be OK.... Bill has stored it in %node%

Steve

Author

Commented:
ah yes I see my mistake... let me test again
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
Hmm, I don't understand that.  Are you checking the Node variable afterwards?  And folder doesn't have a trailing backslash right.

I'm attaching my test, seems to work, maybe this will clarify.

~bp
===== TEST.BAT =====
@echo off
 
set folder=t:\folder\subfolder
 
call :LastNode "%folder%"
 
echo Folder=[%folder%]
echo Node=[%Node%]
goto :EOF
 
:LastNode
set Node=%~n1
goto :EOF
 
 
===== OUTPUT =====
Folder=[t:\folder\subfolder]
Node=[subfolder]

Open in new window

Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
Sorry, should have been more clear in my first post to pull the result from %Node%.  Glad it helped.

~bp
VBS code snip.  Should do what you are looking for.

strPath = "t:\folder\subfolder"
WScript.Echo strPath 'Just to verify the text we are starting with
x = InstrRev(strPath, "\", -1, 1) 'To determine the LAST "\" delimiter
WScript.Echo x
strResult = Mid(strPath, 11) 'Parse the text; not the need to add one position.
WScript.Echo strResult 'This should be what you are going for!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.