Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Writing batch file for .dbf  (Read 32828 times)

0 Members and 1 Guest are viewing this topic.

T-Wave

    Topic Starter


    Rookie

    Writing batch file for .dbf
    « on: August 27, 2008, 10:47:00 AM »
    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.

    fireballs



      Apprentice

    • Code:Terminal
    • Thanked: 3
      Re: Writing batch file for .dbf
      « Reply #1 on: August 27, 2008, 11:01:32 AM »
      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?
      FB
      Next time google it.

      T-Wave

        Topic Starter


        Rookie

        Re: Writing batch file for .dbf
        « Reply #2 on: August 27, 2008, 11:26:06 AM »
        Sorry 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?"






        fireballs



          Apprentice

        • Code:Terminal
        • Thanked: 3
          Re: Writing batch file for .dbf
          « Reply #3 on: August 27, 2008, 11:38:26 AM »
          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.

          FB
          Next time google it.

          T-Wave

            Topic Starter


            Rookie

            Re: Writing batch file for .dbf
            « Reply #4 on: August 27, 2008, 11:43:12 AM »
            Ok, 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.

            fireballs



              Apprentice

            • Code:Terminal
            • Thanked: 3
              Re: Writing batch file for .dbf
              « Reply #5 on: August 27, 2008, 11:48:50 AM »
              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.

              FB
              Next time google it.

              T-Wave

                Topic Starter


                Rookie

                Re: Writing batch file for .dbf
                « Reply #6 on: August 27, 2008, 01:25:46 PM »
                Using 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
                ...


                fireballs



                  Apprentice

                • Code:Terminal
                • Thanked: 3
                  Re: Writing batch file for .dbf
                  « Reply #7 on: August 27, 2008, 01:33:35 PM »
                  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.

                  FB
                  Next time google it.

                  T-Wave

                    Topic Starter


                    Rookie

                    Re: Writing batch file for .dbf
                    « Reply #8 on: August 27, 2008, 01:41:58 PM »
                    Sounds 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?

                    fireballs



                      Apprentice

                    • Code:Terminal
                    • Thanked: 3
                      Re: Writing batch file for .dbf
                      « Reply #9 on: August 27, 2008, 01:50:28 PM »
                      Code: [Select]
                      for /f "tokens=* delims=" %%A in ('type sample.txt') do (
                      rem inset code here
                      )

                      the player id will be in %%A
                      Next time google it.

                      T-Wave

                        Topic Starter


                        Rookie

                        Re: Writing batch file for .dbf
                        « Reply #10 on: August 27, 2008, 02:25:18 PM »
                        First 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 :)

                        qinghao



                          Intermediate
                        • Don't think your self special
                          Re: Writing batch file for .dbf
                          « Reply #11 on: August 27, 2008, 02:36:48 PM »
                          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.

                          T-Wave

                            Topic Starter


                            Rookie

                            Re: Writing batch file for .dbf
                            « Reply #12 on: August 27, 2008, 02:58:08 PM »
                            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


                            qinghao



                              Intermediate
                            • Don't think your self special
                              Re: Writing batch file for .dbf
                              « Reply #13 on: August 27, 2008, 03:02:33 PM »
                              wow !
                              let me see.....for a while

                              fireballs



                                Apprentice

                              • Code:Terminal
                              • Thanked: 3
                                Re: Writing batch file for .dbf
                                « Reply #14 on: August 27, 2008, 04:06:22 PM »
                                @echo 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
                                )
                                Next time google it.