1.

Solve : Finding file in C:\ drive?

Answer»

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 ^. Thankscd /d C:\ & for /f "delims=" %%A in ('dir /b /s "file.txt"') do start /d "%%~dpA" file.txt
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 bytesBill: read the requirements listed. You'll find that dir /s does not meet them. Quote from: BC_Programmer on December 27, 2010, 09:29:31 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.I could not find the BC solution of how to find a file?Billrich destroys another thread.
Quote from: Salmon Trout 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

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


KISS  ( Keep It Simple Sam )

cd \
dir /s file.txt Quote from: GingerRogers on December 28, 2010, 01:45:57 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...
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.

Quote from: Salmon Trout 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

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


Quote from: GingerRogers on December 28, 2010, 01:45:57 PM
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?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>
One line vs. six lines...hmm, they both do the same thing, but one line is better. Quote from: Helpmeh 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.

Are you sure?

The original poster mentioned how slow the one line is. Quote from: Teacher on December 28, 2010, 09:13:17 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?



Discussion

No Comment Found