tags:

views:

32

answers:

2

How do I create a Windows script that executes the command

C:\ZP4\AUTOFIXD C:\FOLDER\PARCELS.DBF \HOME\LIST.LAY SKIPFIRST UPLOW

for any and all PARCELS.DBF files that might be in \FOLDER\ and all subdirectories. Ie, the script would be equivalent to

C:\ZP4\AUTOFIXD \FOLDER\PARCELS.DBF \HOME\LIST.LAY SKIPFIRST UPLOW
C:\ZP4\AUTOFIXD \FOLDER\SUBFOLDER1\PARCELS.DBF \HOME\LIST.LAY SKIPFIRST UPLOW
C:\ZP4\AUTOFIXD \FOLDER\SUBFOLDER1\SUBSUBFOLDER2\PARCELS.DBF \HOME\LIST.LAY SKIPFIRST UPLOW

...etc., but only for each PARCELS.DBF file that actually exists.

\HOME\LIST.LAY SKIPFIRST UPLOW are unchanging parameters used by AUTOFIXD.

A: 

If powershell is an option, I'd recommend it.

In PS:

$files = gci -r C:\ | where {$_.Name -eq 'PARCELS.DBF'} 

foreach ($file in $files)
{
     C:\ZP4\AUTOFIXD $file \HOME\LIST.LAY SKIPFIRST UPLOW
}

untested as I don't have ZP4 on this box, but basic premise should work

Taylor
A: 

The for command can iterate over things. So assuming that you either have no Unicode file names or use a TrueType font for your console window:

for /f "delims=" %%x in ('dir /s /b PARCELS.DBF') do C:\ZP4\AUTOFIXD "%%x" \HOME\LIST.LAY SKIPFIRST UPLOW
Joey
thanks, is this also in powershell ?
andrew k
ok, so I tried to run the above script with powershell and I got this error " missing opening '(' after keyword ' for '. "any ideas ?
andrew k
It's not PowerShell. You tagged your question with `batch file` so I gave you a batch file, not a PowerShell script.
Joey
Ok, I made a BAT out of the above sciprt but it won't run. Do I have to substitute the working directory for %%X ??
andrew k
OK, I got it to run but now I get an error "C:\Documents.SCH not found" ???
andrew k
Nevermind, I got it to run now ! Thank, now I just need to add "c:\program files\ZP4\ZP4.exe" to the script so I dont have to open in manualy before running the script each time. Can I just paste "c:\program files\ZP4\ZP4.exe" into the script, or do I have to tell it to first run the exe, then run the script ??
andrew k