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

Author Topic: Finding file in C:\ drive  (Read 4595 times)

0 Members and 1 Guest are viewing this topic.

shanked

    Topic Starter


    Beginner
    • Experience: Familiar
    • OS: Windows Vista
    Finding file in C:\ drive
    « on: December 27, 2010, 03:07:23 PM »
    How could you have a batch file that can start a program that's placed anywhere on the User's account?

    For example if someone moved a .txt file to "C:\Folder" (and i didn't know), in a batch file how could i make it search everywhere for that specific file.

    I know how to locate a specific file when i know where it is
    Code: [Select]
    start /d "C:\Folder" file.txt so this isn't what i'm asking ^. Thanks
    ...

    Salmon Trout

    • Guest
    Re: Finding file in C:\ drive
    « Reply #1 on: December 27, 2010, 05:46:16 PM »
    cd /d C:\ & for /f "delims=" %%A in ('dir /b /s "file.txt"') do @start /d "%%~dpA" file.txt

    lelaallison



      Starter

      • Computer: Specs
      • Experience: Experienced
      • OS: Windows 7
      Re: Finding file in C:\ drive
      « Reply #2 on: December 27, 2010, 09:20:31 PM »
      Code: [Select]
      @echo off
      cd \
      dir /s %1



      C:\test> findtxtfile.bat  file.txt
       Volume in drive C has no label.
       Volume Serial Number is 0652-E41D

       Directory of C:\folder

      12/27/2010  04:22 PM                 7 file.txt
                     1 File(s)              7 bytes

           Total Files Listed:
                     1 File(s)              7 bytes
                     0 Dir(s)  290,484,391,936 bytes free
      C:\> cd  test

      C:\test> findtxtfile.bat  *.pdf
       Volume in drive C has no label.
       Volume Serial Number is 0652-E41D

       Directory of C:\Program Files\Adobe\Reader 9.0\Reader

      05/13/2008  02:13 PM           353,321 PDFSigQFormalRep.pdf
                     1 File(s)        353,321 bytes
      « Last Edit: December 27, 2010, 09:32:36 PM by lelaallison »

      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: Finding file in C:\ drive
      « Reply #3 on: December 27, 2010, 09:29:31 PM »
      Bill: read the requirements listed. You'll find that dir /s does not meet them.
      I was trying to dereference Null Pointers before it was cool.

      lelaallison



        Starter

        • Computer: Specs
        • Experience: Experienced
        • OS: Windows 7
        Re: Finding file in C:\ drive
        « Reply #4 on: December 27, 2010, 09:36:26 PM »
        Lela: read the requirements listed. You'll find that dir /s does not meet them.

        I believe you are right.  The Original Poster and all interested readers will use your solution.
        « Last Edit: December 27, 2010, 09:48:58 PM by lelaallison »

        lelaallison



          Starter

          • Computer: Specs
          • Experience: Experienced
          • OS: Windows 7
          Finding file in C:\ drive
          « Reply #5 on: December 28, 2010, 01:00:29 PM »
          I could not find the BC solution of how to find a file?

          Salmon Trout

          • Guest
          Re: Finding file in C:\ drive
          « Reply #6 on: December 28, 2010, 01:18:19 PM »
          Billrich destroys another thread.

          GingerRogers

          • Guest
          Finding file in C:\ drive
          « Reply #7 on: December 28, 2010, 01:45:57 PM »
          cd /d C:\ & for /f "delims=" %%A in ('dir /b /s "file.txt"') do @start /d "%%~dpA" file.txt

          The above is  a sophisticated solution to a very simple problem.


          KISS  ( Keep It Simple Sam )

          cd \
          dir /s file.txt

          Salmon Trout

          • Guest
          Re: Finding file in C:\ drive
          « Reply #8 on: December 28, 2010, 01:54:10 PM »
          The above is  a sophisticated solution to a very simple problem.


          KISS  ( Keep It Simple Sam )

          cd \
          dir /s file.txt

          ... and comes back and does it again. Ginger, why did you stop dancing with Red Adair?*

          You have not understood the OP's question: find the file and start it, supplying its folder name as a parameter to the start command.

          *Yes, I know...

          Salmon Trout

          • Guest
          Re: Finding file in C:\ drive
          « Reply #9 on: December 28, 2010, 01:56:59 PM »
          Probably time to lock. If the OP wants to use my script sample and has queries they could PM me.

          This Billrich problem really needs sorting out.


          shanked

            Topic Starter


            Beginner
            • Experience: Familiar
            • OS: Windows Vista
            Re: Finding file in C:\ drive
            « Reply #10 on: December 28, 2010, 03:49:49 PM »
            cd /d C:\ & for /f "delims=" %%A in ('dir /b /s "file.txt"') do @start /d "%%~dpA" file.txt

            This works great, but it does take a while :/


            The above is  a sophisticated solution to a very simple problem.


            KISS  ( Keep It Simple Sam )

            cd \
            dir /s file.txt

            This one locates the directory of the file but how could you make it open it up once it has found it?
            ...

            Teacher



              Newbie

              • Computer: Specs
              • Experience: Experienced
              • OS: Windows 7
              Finding file in C:\ drive
              « Reply #11 on: December 28, 2010, 05:18:31 PM »
              When a text file is at commamd prompt or on a line by its self, notepad will open the file automatically

              Code: [Select]
              @echo off
              cd \
              dir /s /b %1
              dir /s /b %1  >  c:\test\displaytxt.bat
              cd  c:\test\
              c:\test\displaytxt.bat

              Output:

              c:\test> findtxt.bat  file.txt
              c:\folder\file.txt

              c:\test>
              « Last Edit: December 28, 2010, 05:34:07 PM by Teacher »

              Helpmeh



                Guru

              • Roar.
              • Thanked: 123
                • Yes
                • Yes
              • Computer: Specs
              • Experience: Familiar
              • OS: Windows 8
              Re: Finding file in C:\ drive
              « Reply #12 on: December 28, 2010, 08:10:35 PM »
              One line vs. six lines...hmm, they both do the same thing, but one line is better.
              Where's MagicSpeed?
              Quote from: 'matt'
              He's playing a game called IRL. Great graphics, *censored* gameplay.

              Teacher



                Newbie

                • Computer: Specs
                • Experience: Experienced
                • OS: Windows 7
                Finding file in C:\ drive
                « Reply #13 on: December 28, 2010, 09:13:17 PM »
                One line vs. six lines...hmm, they both do the same thing, but one line is better.

                Are you sure?

                The original poster mentioned how slow the one line is.

                Salmon Trout

                • Guest
                Re: Finding file in C:\ drive
                « Reply #14 on: December 28, 2010, 11:53:35 PM »
                The original poster mentioned how slow the one line is.

                Dir /s on the system drive is going to be slow whichever way you package it, Bill. Why haven't you been banned yet?