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

Author Topic: setting paths from search result  (Read 3036 times)

0 Members and 1 Guest are viewing this topic.

noahdfear

  • Guest
setting paths from search result
« on: October 16, 2006, 11:59:22 PM »
Hi all,

I need help setting the filename and path, for a secondary search. Scenario is this;

I've done a search of all drives for files of a certain size, and echoed the results to text (showing full path).
I now need to search the files in those results for a string. How do I echo those to the command line with my search parameters?

I have another situation where I have done a specific directory search of all drives, and now need to echo those paths back to get a file list in each directory.

Intent is to use on 9X and NT both.

TIA

QBasicMac

  • Guest
Re: setting paths from search result
« Reply #1 on: October 17, 2006, 10:49:41 AM »
Assuming z.txt contains a list of filenames,
and z.lst is where you want your results:
Code: [Select]
@echo off
time /t>z.lst
for /f %%i in (z.txt) do (
find "Press Enter" %%i >> z.lst 2>&1
)

noahdfear

  • Guest
Re: setting paths from search result
« Reply #2 on: October 20, 2006, 05:59:15 PM »
Thanks QBasicMac. That helped a lot. :)
I had to revise it a bit due to the fact that I forgot to add, that also in the text is the file size, currently listed first (all the same size). Have it working for NT using ' for /F "tokens=2" %%i '. Would using the %%i as shown above work for 9X if filepath was listed first and size second? Or, is there a way I can make it ignore or even retype the list without the file size, then use the ' for /F %%i ' ?

TIA

BTW, what does this do?  2>&1

QBasicMac

  • Guest
Re: setting paths from search result
« Reply #3 on: October 20, 2006, 07:58:38 PM »
dir /b
That will avoid date/time, etc.

2>&1 says to write any error messages to the same place as the regular messages.

example, if you say
type abc.txt
then abc.txt will be typed to the console, right?
and if there is no file abc.txt, an error message instead.

If you say
type abc.txt >mylog.txt
then abc.txt will be type to mylog.txt. But if there is no file abc.txt then an error message will be typed to the console, not abc.txt.

But if you say
type abc.txt >mylog.txt 2>&1
both will go to mylog.txt.

2> is for errors
1> is normal (nobody ever types the "1" but they could)

Mac

QBasicMac

  • Guest
Re: setting paths from search result
« Reply #4 on: October 20, 2006, 08:03:49 PM »
Uh, yep, the tokens stuff should work if you can't avoid the date. What exactly did you use to build the list?

I know of no way to get files smaller than x, such as

dir *.* /size<5K /b /s >Mylist.txt

(bombs out like crazy - LOL)


noahdfear

  • Guest
Re: setting paths from search result
« Reply #5 on: October 20, 2006, 08:19:08 PM »
Thanks for that explanation Mac ...... I'm sure I'll be using it in the future  ;)

Actually, I need the size. I first do a search of all files by K size>> 1my.txt
then sort that by a byte size and exclude certain directories >> 2my.txt
It's from 2my.txt that I need to search the remaining files by string.

TIA

QBasicMac

  • Guest
Re: setting paths from search result
« Reply #6 on: October 20, 2006, 08:22:07 PM »
Quote
TIA

TIA?  Is there an outstanding question? LOL. I thought I was finished here.

noahdfear

  • Guest
Re: setting paths from search result
« Reply #7 on: October 20, 2006, 08:35:52 PM »
Maybe I misunderstood your previous post...........

Quote
Uh, yep, the tokens stuff should work if you can't avoid the date.

Were you suggesting that tokens will work in 9X?

QBasicMac

  • Guest
Re: setting paths from search result
« Reply #8 on: October 20, 2006, 09:00:46 PM »
Sorry, my friends tell me 98 does not support
date /t
so I don't know how you get the date there.

Bummer

Mac

noahdfear

  • Guest
Re: setting paths from search result
« Reply #9 on: October 20, 2006, 09:16:57 PM »
Think we got crossed somewhere on what I'm trying to achieve.

I have a text file of filenames with path, and the file size. File size precedes the path/name.

I need to search every file in that text for a string and output the results to another text.

No date involved, and it's my understanding that 9X does not support tokens option, therefore the use of ' for /f %%i in (my.text) do find "string" %%i >> my2.txt' will try to search the string from the filesize rather than the path/filename. Will putting the filesize after the path in my.txt allow it to search the files?

example of current my.txt

19225   C:\windows\filen.ame
19225   C:\progra~1\Norton\filen.ame


if changed to,

C:\windows\filen.ame   19225  
C:\progra~1\Norton\filen.ame   19225  

will %%i search the files for string as if the size isn't even present?

QBasicMac

  • Guest
Re: setting paths from search result
« Reply #10 on: October 21, 2006, 09:00:34 AM »
Quote
T
will %%i search the files for string as if the size isn't even present?

I'm pretty sure. The variable, %%i, will be set to the first string up to a space, the default delimiter.

At least I know the following works on NT4:
Code: [Select]
echo C:\windows\filen.ame   19225    > z.txt
echo C:\progra~1\Norton\filen.ame   19225    >>z.txt
for /F %%i in ('type z.txt') do (
echo Got a filename
echo It's name is %%i
echo So I am happy
)

Mac


noahdfear

  • Guest
Re: setting paths from search result
« Reply #11 on: October 21, 2006, 09:43:19 AM »
Thanks. I'll give it a try on 9X.