post #1 of 1
Thread Starter 
I have been trying to create a batch file that compacts and repairs a list of databases in a folder. The job would be easy to accomplish except that the filenames that need to be repaired change with every customer I have. There are sometimes .mdb files as well as .accdb files which isn't an issue because the same command works for both. They are named with dates such as:

10-22-2010.mdb
10-23-2010.mdb
11-25-2011.accdb
11-26-2011.accdb

So if the list of names were static I wouldn't have an issue since I could just write a line for each of the filenames that will be encountered like this:
Code:
"C:\Program Files (x86)\Microsoft Office\Office14\msaccess.exe" "C:\databases\10-22-2010.mdb" /compact
"C:\Program Files (x86)\Microsoft Office\Office14\msaccess.exe" "C:\databases\10-23-2010.mdb" /compact
"C:\Program Files (x86)\Microsoft Office\Office14\msaccess.exe" "C:\databases\10-25-2010.accdb" /compact
"C:\Program Files (x86)\Microsoft Office\Office14\msaccess.exe" "C:\databases\10-26-2010.accdb" /compact

This will work in a batch file if those were the only 4 files there. The problem, is that the filenames never start or finish at the same time, so if I use this batch file and the dated files begin at "10-23-2010.mdb" the batch fails at the first line because it cannot find the first specified file. Is there any way I can have the batch file skip any filenames that are not found? I have tried using wildcards with no luck.

Thanks for any help.

EDIT- Figured it out myself with a lot of searching and trail-and-error. Solution is:
Code:
@echo off
if exist C:\databases\10-22-2010.mdb (goto :existing) else goto :missing
:existing
"C:\Program Files (x86)\Microsoft Office\Office14\msaccess.exe" "C:\databases\10-22-2010.mdb" /compact
:missing
if exist C:\databases\10-23-2010.mdb (goto :existing) else goto :missing
:existing
"C:\Program Files (x86)\Microsoft Office\Office14\msaccess.exe" "C:\databases\10-23-2010.mdb" /compact
:missing
if exist C:\databases\10-25-2010.accdb (goto :existing) else goto :missing
:existing
"C:\Program Files (x86)\Microsoft Office\Office14\msaccess.exe" "C:\databases\10-25-2010.accdb" /compact
:missing

Etc.. etc.. etc..

Hope this may help someone in the future.
Edited by PhillyOverclocker - 11/5/13 at 2:37pm
My System
(17 items)
 
  
CPUMotherboardGraphicsGraphics
AMD Phenom II X4 955  Gigabyte GA-MA790XT-UD4P Sapphire HD 6950 Sapphire HD 6950 
RAMHard DriveHard DriveOptical Drive
G-Skill Mushkin Callisto Deluxe WD Black LG Supermulti 
CoolingOSKeyboardPower
Rasa Black CPU water block. Rasa X20 pump/res c... Windows 7 Ultimate x64 Deck Legend Fire mechanical with Cherry Black s... Cooler Master Silent Pro Gold 1200W modular PSU. 
CaseMouseAudio
Cooler Master Storm Scout Logitech MX-518 Logitech Wireless headset for gaming and 100w M... 
  hide details  
Reply
My System
(17 items)
 
  
CPUMotherboardGraphicsGraphics
AMD Phenom II X4 955  Gigabyte GA-MA790XT-UD4P Sapphire HD 6950 Sapphire HD 6950 
RAMHard DriveHard DriveOptical Drive
G-Skill Mushkin Callisto Deluxe WD Black LG Supermulti 
CoolingOSKeyboardPower
Rasa Black CPU water block. Rasa X20 pump/res c... Windows 7 Ultimate x64 Deck Legend Fire mechanical with Cherry Black s... Cooler Master Silent Pro Gold 1200W modular PSU. 
CaseMouseAudio
Cooler Master Storm Scout Logitech MX-518 Logitech Wireless headset for gaming and 100w M... 
  hide details  
Reply