Link to home
Start Free TrialLog in
Avatar of Peter Wilcox
Peter WilcoxFlag for United States of America

asked on

Dos FOR loop question

Here is my batch file.

For /f %%a IN (‘R:\ /b *.mdb’) do call "C:\Program Files\Microsoft Office\Office14\msaccess.exe" %%a /compact


I am trying to run through the R drive and grab all the .mdb's and do compact from msaccess but when I run this through command prompt I get this error:

%%a was unexpected at this time

Any suggestions on how to get this For loop command to work properly.
Avatar of Peter Wilcox
Peter Wilcox
Flag of United States of America image

ASKER

Avatar of Lee W, MVP
you cut and paste, didn't you?  

:-)

You have:
For /f %%a IN (‘R:\ /b *.mdb’) do call "C:\Program Files\Microsoft Office\Office14\msaccess.exe" %%a /compact
try
For /f %%a IN ('R:\ /b *.mdb') do call "C:\Program Files\Microsoft Office\Office14\msaccess.exe" %%a /compact

(Note the TYPE of quote surrounding R:\ /b *.mdb)
I did but I still get the same message...
3-4-2011-4-40-03-PM.jpg
I think he means:

  IN ('dir/s/b R:\*.mdb')
... and if any of your .mdb files have spaces in the name, put quotes here:  "%%a" /compact
Oh and the obvious... if you are typing that at the command line use %a instead of %%a (which is for batch files).

Steve
SOLUTION
Avatar of Farhan Kazi
Farhan Kazi
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry Steve, didn't refresh the page :(
Is there a way to exclude specific MDB's?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial