[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 939
  • Last Modified:

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.
0
goretailpro
Asked:
goretailpro
  • 3
  • 2
  • 2
  • +2
2 Solutions
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
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)
0
 
goretailproAuthor Commented:
I did but I still get the same message...
3-4-2011-4-40-03-PM.jpg
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
knightEknightCommented:
I think he means:

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

Steve
0
 
Farhan KaziSystems EngineerCommented:
@goretailpro:
Are you executing above statement from command line? if yes then you need to remove one % sign from FOR statement.

FOR /F "delims=*" %a IN ('DIR /b /s R:\*.mdb') do call "C:\Program Files\Microsoft Office\Office14\msaccess.exe" "%a" /compact

in batch file, following should work:

FOR /F "delims=*" %%a IN ('DIR /b /s R:\*.mdb') do call "C:\Program Files\Microsoft Office\Office14\msaccess.exe" "%%a" /compact

Hope this helps!
Farhan
0
 
Farhan KaziSystems EngineerCommented:
Sorry Steve, didn't refresh the page :(
0
 
goretailproAuthor Commented:
Is there a way to exclude specific MDB's?
0
 
Steve KnightIT ConsultancyCommented:
You could have a list of entries to exclude in a text file perhaps, e.g.

somefile.mdb
another.mdb
c:\someexcludedir

then use a find /v command as part of the dir command to exclude those lines, they would only need to be a partial match (but not wildcards), e.g. if you want to exclude a whole subdir worth then include that path in the file

@echo off
set exclude="r:\exclude.txt"
FOR /F "delims=*" %%a IN ('DIR /b /s R:\*.mdb ^|findstr /i /v /g:%exclude%') do call "C:\Program Files\Microsoft Office\Office14\msaccess.exe" "%%a" /compact

That says to take the dir listing of all MDB files in the R: drive and all subdirs then pass that to findstr to find all lines that do NOT match any of the search strings in the r:\exclude.txt file.



Steve
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now