1.

Solve : Writing batch file for .dbf?

Answer»

Good day  ,

I would like to write a batch file to automate a tedious and repetitive task. Unfortunately, I have little to no experience with writing batch files, so I hope I can get the appropriate guidance from here.

The Situation: I have two .dbf files of a game, namely player.dbf and appearance.dbf. The changes I want to make is to the heights of the players which can be found under a field called HEIGHT in the appearance.dbf file.

In the appearance.dbf file, each player has a unique appearance ID which is identical to the unique player ID found in the player.dbf file.

To identify which players' heights I want to CHANGE, I need to use the player.dbf file to get their player IDs then map this player ID to the appearance ID in the appearance.dbf file and finally make the changes.

The Problem: How do I make a batch file to open one .dbf file(in this case, player.dbf), read its content(player ID), use that content to identify the field to be updated in a second .dbf file(appearance.dbf)? Or is there a more efficient way to carry this task out?

I hope I've been able to express my problem clearly. Any help will be very appreciated. Thanks.you should probably have put this in the DOS forum but n/m

What do the .dbf files look like - are they human readable? what form does the information take? can you post a picture of a .dbf file opened with a text editor?
FBSorry about posting this in the wrong forum. I'm not familiar with how things are organised around here.

The .dbf files are human readable as can be seen in the first screenshot. The second picture is of the .dbf file opened in a text editor. Not sure what you meant by "what form does the information take?"





From what the text editor looks like i can't help you, there are a few other guys who know DOS better than i do that might.

Only other option i can think of is to root around the menus/help documents for a macro maker/editor.


Something like this: "Execute scripts, using the SQL editor." which i found on there website, though i'm definitely not up to telling you how to script in SQL.

FBOk, thanks nevertheless

Curious: Is there a way to link this topic to the DOS forum? Sounds like I might be able to get more responses to this topic from there.I'll PM one of the moderators and get them to move it.

If you do want to ask about SQL the computer programming SECTION is the place to do it.

FBUsing CDBFlite, I got the batch file to extract the player IDs I need from the player.dbf file and save this information in a .txt file. I'm thinking it should be easier now to write another batch file that gets the player IDs from the .txt file and uses it as if it were the appearance ID in appearance.dbf (since they are identical) in order to identify the heights in to be edited.

Perhaps someone knows a SOLUTION to this: How do I use the content of a .txt file as input to a batch program? By the way, my .txt file after extracting the player IDs from player.dbf looks like this:

4017
4022
4023
4028
...

you can use the playerID in a batch file but you need the heights to be in a text file also for DOS to be able to use them.

FBSounds good.

Actually, all I want to do is to set different groups of players to a fixed height if they are below a particular height. So my batch program checks to see if the player with a particular appearance ID is smaller than the base height(in my case 6'6). If so, it sets his height to 6'6. My batch file can do this ALREADY, all it NEEDS is to get the player IDs from the .txt file it created. How do I do this? Code: [Select] for /f "tokens=* delims=" %%A in ('type sample.txt') do (
rem inset code here
)
the player id will be in %%AFirst of all, thanks a lot, Fireballs, for your effort.

I'm not sure were exactly to put the code you gave me, so I'll just explain what I have already.

"cdbflite.exe" players.dbf /case /filter:TEAM=39 /filter:POSITION=3;POSITION=2 /out:Wing.txt /select:PLAYERID /update

I have the above code this way in my first batch file because the computer generated players are generally undersized. When they are generated, they are all in TEAM #39. Players playing the position 3 and 2 tend to be about the same size, so my batch file filters them out together and stores their respective player IDs in Wing.txt

After running that batch file, the Wing.txt looks somewhat like this:

 4017
 4022
 4023
 4028
 ...

In a second batch file,  I have the following code:

"cdbflite.exe" appearance.dbf /case /filter:APPEARID= /filter:HEIGHT{78 /field:HEIGHT=78 /update

This second one is as of now incomplete, pending a way to get the player IDs stored in Wing.txt and equating them to APPEARID in the code above. 

Do I insert your code in this second batch file? If so, where?

If I understood the instructions in your code, it should look like this:

for /f "tokens=* delims=" %%A in ('Wing.txt') do ("cdbflite.exe" appearance.dbf /case /filter:APPEARID= /filter:HEIGHT{78 /field:HEIGHT=78 /update )

I however do not see where APPEARID is being equated to the line being extracted from Wing.txt. Is there something I'm missing? Pardon my ignorance you shoud give us the whole structure of the DB and post up the sample file!

one more thing,I think this can't be done with DOS command.Qinghao, I don't know what you mean by the whole structure of the DB, but in the picture below, which I posted earlier, on the left panel, the players.dbf file is open and on the right panel, the appearance.dbf is open. If you look keenly, you'll see the PLAYERID which is the fourth column in the players.dbf(left panel) and the APPEARID which is the 2nd column in the appearance.dbf(right panel). Also, what sample file are you talking about? If you mean my batch files, then I've included their codes below.



First batch file:
Code: [Select]ECHO OFF
:start
CLS
ECHO.
ECHO
ECHO                    GENERATED ROOKIE HEIGHT FIX
ECHO.
ECHO If you do not want to install the patch, close the window now.
ECHO.
ECHO PRESS ANY KEY TO CONTINUE
pause >nul
ECHO.
ECHO FIXING GENERATED ROOKIE HEIGHTS
ECHO.
ECHO.

ECHO Shooting Guards and Small Forwards
"cdbflite.exe" players.dbf /case /filter:TEAM=39 /filter:POSITION=3;POSITION=2 /out:Wing.txt /select:PLAYERID /update

ECHO.
:end
ECHO Players.dbf updated
ECHO PATCH INSTALLED
ECHO.
ECHO.
ECHO Press any key to close this window
pause >nul
EXIT
2nd batch file
Code: [Select]ECHO.
ECHO PRESS ANY KEY TO CONTINUE
pause >nul
ECHO.
ECHO FIXING GENERATED ROOKIE HEIGHTS
ECHO.
ECHO.

ECHO Shooting Guards and Small Forwards
"cdbflite.exe" appearance.dbf /case /filter:APPEARID= /filter:HEIGHT{78 /field:HEIGHT=78 /update

ECHO.
:end
ECHO Players.dbf updated
ECHO PATCH INSTALLED
ECHO.
ECHO.
ECHO Press any key to close this window
pause >nul
EXIT
wow !
let me see.....for a whileecho off
 for /f "tokens=* delims=" %%A in ('type sample.txt') do (
rem inset code here
set APPEARID=%%A

ECHO.
ECHO PRESS ANY KEY TO CONTINUE
pause >nul
ECHO.
ECHO FIXING GENERATED ROOKIE HEIGHTS
ECHO.
ECHO.

ECHO Shooting Guards and Small Forwards
"cdbflite.exe" appearance.dbf /case /filter:APPEARID= /filter:HEIGHT{78 /field:HEIGHT=78 /update

ECHO.
:end
ECHO Players.dbf updated
ECHO PATCH INSTALLED
ECHO.
ECHO.
ECHO Press any key to close this window
pause >nul
EXIT
)



Discussion

No Comment Found