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

Author Topic: Search file and edit it  (Read 14707 times)

0 Members and 1 Guest are viewing this topic.

Apexi

    Topic Starter


    Rookie

    Search file and edit it
    « on: March 24, 2011, 10:08:01 AM »
    Hi guys. I need some help with a batchfile i working on.
    Lets say i want to search for a file that is located somewere in C:\
    The file is a .vdf and editable with notepad. Simply i want to edit some text to that file at the end of all other text.

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Search file and edit it
    « Reply #1 on: March 24, 2011, 11:10:21 AM »
    Here is a start
    Code: [Select]
    C:
    cd \
    dir *.vdf /s /b >list.txt
    The above makes a list of all such files with the path.
    That is as much as I know.

    Apexi

      Topic Starter


      Rookie

      Re: Search file and edit it
      « Reply #2 on: March 24, 2011, 12:15:04 PM »
      No you misunderstood me  :)
      Let me put it this way. I have a file named test.vdf contain some text and i dont know where the file is located.
      First of all the test.vdf file have to be found, then automaticly insert some text into the test.vdf file at the end after the original text. Not rewrite.

      And if this is possible. Whats the command to change directory automaticly to the file when its found by dir *text.vdf*.* /s
      « Last Edit: March 24, 2011, 12:25:11 PM by Apexi »

      col. sanders



        Rookie

        • Experience: Beginner
        • OS: Unknown
        Re: Search file and edit it
        « Reply #3 on: March 24, 2011, 12:28:10 PM »
        Here ya go.  You needed two ">>".  This will find it, and "append" to the end of the original text you use, not replace it.

        cd\
        dir/s/p/b \*.vdf >> test.vdf


        Apexi

          Topic Starter


          Rookie

          Re: Search file and edit it
          « Reply #4 on: March 24, 2011, 01:16:07 PM »
          Does not work properly.

          BC_Programmer


            Mastermind
          • Typing is no substitute for thinking.
          • Thanked: 1140
            • Yes
            • Yes
            • BC-Programming.com
          • Certifications: List
          • Computer: Specs
          • Experience: Beginner
          • OS: Windows 11
          Re: Search file and edit it
          « Reply #5 on: March 24, 2011, 01:28:03 PM »
          I was trying to dereference Null Pointers before it was cool.

          Salmon Trout

          • Guest
          Re: Search file and edit it
          « Reply #6 on: March 24, 2011, 01:36:18 PM »
          What kind of file is this vdf? Is it an Avira virus definition file? You don't where it's located, but you want to modify it. Hmmmm......
           

          Geek-9pm


            Mastermind
          • Geek After Dark
          • Thanked: 1026
            • Gekk9pm bnlog
          • Certifications: List
          • Computer: Specs
          • Experience: Expert
          • OS: Windows 10
          Re: Search file and edit it
          « Reply #7 on: March 24, 2011, 01:44:08 PM »
          What kind of file is this vdf? Is it an Avira virus definition file? You don't where it's located, but you want to modify it. Hmmmm......
          It must be a conspiracy.   >:(

          Salmon Trout

          • Guest
          Re: Search file and edit it
          « Reply #8 on: March 24, 2011, 01:45:08 PM »
          It must be a conspiracy.   >:(

          Not necessarily, but it makes me curious.

          Apexi

            Topic Starter


            Rookie

            Re: Search file and edit it
            « Reply #9 on: March 24, 2011, 02:31:27 PM »
            No worries. I dont really know what .vdf stands for, but it belongs to Steam. All of the saved online servers ends up in that file. Sometimes the saved server dissapear, a well known bug. Since me and my friends have Steam installed on different directories the batch script need to find the place first.

            Salmon Trout

            • Guest
            Re: Search file and edit it
            « Reply #10 on: March 24, 2011, 02:36:11 PM »
            No worries. I dont really know what .vdf stands for, but it belongs to Steam. All of the saved online servers ends up in that file. Sometimes the saved server dissapear, a well known bug. Since me and my friends have Steam installed on different directories the batch script need to find the place first.

            If you are talking about masterserver.vdf, I read this...

            Quote
            Making the VDF read-only prevents your game or Steam from overwriting it in some cases.




            Apexi

              Topic Starter


              Rookie

              Re: Search file and edit it
              « Reply #11 on: March 24, 2011, 03:09:29 PM »
              Not really what i looking for but thanks anyway. Since no one can help me out i'll have to ask another question.
              Whats the command to change directory automaticly to the file when its found by dir *text.vdf*.* /s

              Salmon Trout

              • Guest
              Re: Search file and edit it
              « Reply #12 on: March 24, 2011, 03:14:30 PM »
              Not really what i looking for but thanks anyway. Since no one can help me out i'll have to ask another question.
              Whats the command to change directory automaticly to the file when its found by dir *text.vdf*.* /s

              for /f "delims==" %%A in ('dir *text.vdf*.* /s') do (
                  set filefolder="%%~dpA"
                  set filepathandname="%%~dpnxA"
                  )


              Apexi

                Topic Starter


                Rookie

                Re: Search file and edit it
                « Reply #13 on: March 24, 2011, 03:48:28 PM »
                Did not either work. I just end up in the same directory i begin at.

                Salmon Trout

                • Guest
                Re: Search file and edit it
                « Reply #14 on: March 24, 2011, 03:55:58 PM »
                Did not either work. I just end up in the same directory i begin at.

                what happens if you put

                echo "%%~dpnxA"

                in the script?

                and what's with the second wildcard in this?

                *text.vdf*.*

                I suspect it's not finding anything, as it's looking for a file with 2 dots