Opening a folder that starts with some charaters

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
rtown
Posts: 2
Joined: 12 Jun 2013 15:43

Opening a folder that starts with some charaters

#1 Post by rtown » 12 Jun 2013 15:58

Hello,
I need some help finishing this up. Its going to be a shortcut to opening a specific folder in a very large directory structure.

An example folder location would be \\SERVER923\data\10900-10999\10956-somename-anothername
I want the user to open the batch file, enter 5 digits, hit enter and have it open explorer to that folder that starts with those 5 digits
I have this complete except for the "-somename-anothername" part. Basically I dont care what this part of the folder name is, all I care about is the 5 digit number. I have tried to add a wildcard character after the 5 digits as seen below but it does not work... any assistance would be helpful! :D

Code: Select all

@echo off
setlocal enableextensions enabledelayedexpansion
set /p UserInput=Enter a number:
set /a Test=UserInput
if !Test! EQU 0 (
  if !UserInput! EQU 0 (
    echo !UserInput!
  ) else (
    echo Not a number
  )
) else (
  echo !UserInput!
  set start=!UserInput:~0,3!
  set end=!UserInput:~0,3!
 
  %SystemRoot%\explorer.exe "\\SERVER923\data\!start!00-!end!99\!UserInput!-*"
)

Aacini
Expert
Posts: 1932
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Opening a folder that starts with some charaters

#2 Post by Aacini » 12 Jun 2013 16:37

Code: Select all

for /D %%a in ("\\SERVER923\data\!start!00-!end!99\!UserInput!-*") do (
   %SystemRoot%\explorer.exe "%%~a"
)

rtown
Posts: 2
Joined: 12 Jun 2013 15:43

Re: Opening a folder that starts with some charaters

#3 Post by rtown » 12 Jun 2013 17:06

rtown wrote:
Aacini wrote:

Code: Select all

for /D %%a in ("\\SERVER923\data\!start!00-!end!99\!UserInput!-*") do (
   %SystemRoot%\explorer.exe "%%~a"
)


This doesn't seem to work. In tried placing this in the else section and outside it... am I missing something? :(


Wooops. Nevermind... It works!! Thanks so much Aacini! :D

Post Reply