There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios boot browser bsod computer cpu crash css dell desktop driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware help please hijackthis hjt install internet internet explorer itunes javascript keyboard lan laptop log malware monitor network networking openoffice outlook outlook 2003 password php popups problem router seo slow sound sp3 spyware startup trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
DOS/PDA/Other
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Operating Systems > DOS/PDA/Other >
Solved: Use of Wildcards


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
gamecockfan's Avatar
Computer Specs
Senior Member with 835 posts.
 
Join Date: Dec 2007
Location: HERE OR THERE?!?!?!
Experience: Always Learning!
15-May-2008, 03:09 PM #1
Question Solved: Use of Wildcards
I am trying to create a batch file that will open an excel file.

Here is what I have so far....

Code:
start excel.exe "C:\weekending *.xls"
I am trying to use a wildcard that will find/determine the remaining filename. The rest of the filename is a date, and will change on a weekly basis so I cannot hard code the filename.

Does anyone know how to use wildcards in a batch file?

Any help with this will be greatly appreciated.
__________________
GamecockFan

“Give, and it shall be given to you. For whatever measure
you deal out to others, it will be dealt to you in return.”
(Luke 6:38)
___________________________________________________

"Imagination is more important than knowledge. Knowledge
is limited. Imagination encircles the world." (Albert Einstein)
TheOutcaste's Avatar
Computer Specs
Senior Member with 1,538 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
15-May-2008, 08:31 PM #2
Seems Excel won't accept wildcards for filenames. You can open multiple files, but have to give the full name.
So, a For statement will do the trick:
(note that those are not single quotes around the dir command, they are Accent Graves)
Code:
@echo off
set filepath=c:\test1\
For /f "usebackq tokens=*" %%I in (`dir /b /a-d "%filepath%weekending*.xls"`) do start /I excel.exe "%%I"
Be sure to change the path in the set statement as needed. You can also just specify it in the For command.

Note that this will open EVERY spreadsheet in the folder that starts with weekending

If these spreadsheets are stored in this same folder and you just want to open the one for the previous week, it would be easiest to create a macro in an Excel spreadsheet that gets the weekending date for the previous week and then opens that file. The batch program would then just open the spreadsheet with the autorun macro.

The folks in the Business Applications Forum can probably whip up a macro or VB script to do that for you.

HTH

Jerry


__________________
Of course I know all the answers ; I just don't always match the answers to the right questions

Warning -- Windows spoken here. (Rated R for Strong Language and Violence -- When your Windows PC flies through a window, that's violent, right?)
madd74's Avatar
Computer Specs
Senior Member with 202 posts.
 
Join Date: Nov 2003
Location: Des Moines, IA
Experience: Advanced
16-May-2008, 07:39 PM #3
another option would be to use:

start excel.exe "C:\weekending %1.xls"

then you would type after the BATCH file what you wanted run, for example, if you wanted to run the file test.xls you would do

batchfile test

and if batchfile is the .bat it would run, but of course, that requires you knowing and running the actual name of the file
__________________
madd says check out Madd's World - Red Mage of the Net (madd74.com) or chat with me and friends live! or visit madd on myspace
gamecockfan's Avatar
Computer Specs
Senior Member with 835 posts.
 
Join Date: Dec 2007
Location: HERE OR THERE?!?!?!
Experience: Always Learning!
22-May-2008, 10:33 AM #4
TheOutcaste,

I tried your method. However I get an error message that shows the Excel filename (which is correct), but teh error message states that the file cannot be found. I have the Excel found located on the C: drive for testing.
TheOutcaste's Avatar
Computer Specs
Senior Member with 1,538 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
22-May-2008, 12:01 PM #5
If the weekending*.xls file is in the root of the C drive, meaning the full path is C:\Weekending05-17.xls for example, make sure you changed the filepath line in the batch file:

change:
set filepath=c:\test1\
to
set filepath=c:\

If you still get an error, can you paste the error here? Right click in the command prompt window, choose Select All, then press enter.
CTRL+V in the reply window will paste the contents of the command prompt window.

Jerry
__________________
Of course I know all the answers ; I just don't always match the answers to the right questions

Warning -- Windows spoken here. (Rated R for Strong Language and Violence -- When your Windows PC flies through a window, that's violent, right?)
gamecockfan's Avatar
Computer Specs
Senior Member with 835 posts.
 
Join Date: Dec 2007
Location: HERE OR THERE?!?!?!
Experience: Always Learning!
22-May-2008, 12:06 PM #6
I have attached a screenshot of the error message that comes up when the batch file is ran.
Attached Files
File Type: zip Error Message.zip (21.9 KB, 2 views)
TheOutcaste's Avatar
Computer Specs
Senior Member with 1,538 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
22-May-2008, 12:35 PM #7
Opps, my booboo, forgot to put the filepath variable into the start statement.
Try this (change is in red)

Code:
 @echo off
set filepath=c:\test1\
For /f "usebackq tokens=*" %%I in (`dir /b /a-d "%filepath%weekending*.xls"`) do start /I excel.exe "%filepath%%%I"
I usually put my test scripts in one folder, and the sample files in another to catch these senior moments, but I managed to have the batch file and the sample xls files in the same folder and missed it this time.
Jerry
__________________
Of course I know all the answers ; I just don't always match the answers to the right questions

Warning -- Windows spoken here. (Rated R for Strong Language and Violence -- When your Windows PC flies through a window, that's violent, right?)
gamecockfan's Avatar
Computer Specs
Senior Member with 835 posts.
 
Join Date: Dec 2007
Location: HERE OR THERE?!?!?!
Experience: Always Learning!
22-May-2008, 12:36 PM #8
Jerry,

That worked perfectly. Thank you very much.
TheOutcaste's Avatar
Computer Specs
Senior Member with 1,538 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
22-May-2008, 12:40 PM #9
You're Welcome!

Please mark solved if your issue is resolved using the Mark Solved button at the top left of this thread.

Jerry
gamecockfan's Avatar
Computer Specs
Senior Member with 835 posts.
 
Join Date: Dec 2007
Location: HERE OR THERE?!?!?!
Experience: Always Learning!
22-May-2008, 12:40 PM #10
How would I do the "FilePath" if the Excel file is found on the server?

For Example: \\server\folder1\folder2\my folder\folder 3

I tried placing the path in the "FilePath", but when I run the batch file the command prompt flashes on the screen and nothing happens.
TheOutcaste's Avatar
Computer Specs
Senior Member with 1,538 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
22-May-2008, 12:50 PM #11
if the file is \\server\folder1\folder2\my folder\folder 3\weekending 05-24-2008.xls
use
set filepath=\\server\folder1\folder2\my folder\folder 3\
The trailing slash is needed.

Or, change the For statement to include the slash:
For /f "usebackq tokens=*" %%I in (`dir /b /a-d "%filepath%\weekending*.xls"`) do start /I excel.exe "%filepath%\%%I"

You might be able to do both, but it may not work on all versions of Windows/DOS

Jerry
__________________
Of course I know all the answers ; I just don't always match the answers to the right questions

Warning -- Windows spoken here. (Rated R for Strong Language and Violence -- When your Windows PC flies through a window, that's violent, right?)
gamecockfan's Avatar
Computer Specs
Senior Member with 835 posts.
 
Join Date: Dec 2007
Location: HERE OR THERE?!?!?!
Experience: Always Learning!
22-May-2008, 01:10 PM #12
That did the job. Thank you.
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 06:28 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.