Solved

get file name in batch file

Posted on 2004-09-23
3
1,092 Views
Last Modified: 2008-03-17
Can I get file name in batch file:
1. Input a text string
2. find the file including input string in current dir
3. display the file name
0
Comment
Question by:Yuanyu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 50 total points
ID: 12139910
Not sure I completely understand, but depending on your OS - you can try:

@echo off
set /p filename=Which file would you like to search for?
dir .\%filename%
echo %filename%
0
 

Author Comment

by:Yuanyu
ID: 12139991
The string I inputed is only part of filename, for example, when I input '12', I like to get '*12*.*'
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 12142097
I didn't understand that from your original question - why did you accept this one if it wasn't a complete answer?
I shoot for an "A" grade, so...
Change the "dir" line to

dir .\*%filename%*

and that should do it for you! : )
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

691 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