Calling all batch file gurus

::switch to folder log
cd log
::Make a folder called files
mkdir files
::search for htm files in the currect dir that contain the string “text” and move ::them to dir files
for %%f in (*.htm) do find /n “Text” %%f | move files
cd…

I want the above batch file to look through a set of htm files in a given directory for the string “text.” Then, move those files that contain the string to a directory that is made called files

Can someone let me know what is wrong and tell me how to fix it?

or any alternitive solutions?

thanks

dante

i could probably make a simple .exe that would do this… but only on windows/dos. do you want the program to search inside the file or just the filename?

It must search inside the file for the string or strings…

your help would be GREATLY appreciated!

dante

any other suggestions?

dante

I think the MOVE FILES needs to be extended more…

I’m getting this info from http://www.computerhope.com/batch.htm which is a likely place you searched…

I also think you maybe trying to do too much at once… if you can break it down or try another way… possibly get a batch file to move all .htm files to a folder… then make another which can search for text…

I noticed it said the FIND command IS CASE SENSITIVE…

Make sure you have a file called FILES in the first place.

for %%f in (*.htm) 

What is the %%f ? I know it said use %% in a batch file… but the F? is this a number you specify when running the batch file?

do find /n "Text" %%f | move files

I’m not sure what the /n does. If you can look at the code and explain to me EXACTLY what it’s doing… then you’ll realise the problem yourself… move files doesn’t seem enough information for DOS to understand what’s happening…

and what’s the ’ | ’ all about?

look at it again :wink:

it all works except the move command, for which I cant find a way to specify the source file to copy to the dir FILES.

%%f is the system var for the current directory.

I also think you maybe trying to do too much at once… if you can break it down or try another way… possibly get a batch file to move all .htm files to a folder… then make another which can search for text…

Its not a problem of searching, nor a problem of moving. Its a problem of searching to FIND files containing the specified text (which the batch file does just fine) AND MOVING those specific files containing the text.

This isnt a problem having to do with the case sensitive search.

Make sure you have a file called FILES in the first place.

Its one of the first lines of code I have written, except its a folder. Not a file.

Th pipe or " | " is for redirecting output to the move command, which doesnt work, which is why im asking for help.

thanks

dante

check to see if you can find a program like grep for dos/windows that can search for text in files. cygwin probably has it- I don’t know how much of the cygwin environment you would have to install for it to work. More likely you can find an equivelant or a native dos version.

hmm… im not sure if i could make something that could search INSIDE the files… but i could probably make something that searches file names.

If I could just find a way to use an input file which contains the names of the files I want to delete, I would be fine. Something like

del | input.txt

This doesnt work, obviously… Anyone know how I could do this?

thanks

dante

Could you write a program that will input a text file and display a give line of text. For example, the text file is

  1. This is a text file
  2. It is full of text
  3. Lots and lots of text
  4. Look! Its more text!

At the command line I would type “program textfile.txt 1”
which would output: “This is a text file”

‘program’ being the name of the program
‘textfile.txt’ being the input text file
‘1’ being the specified line number

Typing “program textfile.txt 2” would output:
“It is full of text”

I think then I could use the program’s output in the batch file to along with a counter to delete all of the files on the list.

It would also be useful if there were a parameter that would output the maximum number of lines that are in the text file

Your help would be GREATLY GREATLY appreciated!

dante

okeydokes dante, i just finished making an exe that will do exactly what you requested above.

for example, if text.txt reads
Tralalal
doododo
teeteeta

then typing at the command prompt: reader.exe text.txt 2
will output: doododo

well, tell me if it works for you!

(right click and save target as…)
http://www.webspace4free.biz/blenergetic/reader.zip

C:\downloads\strings>reader.exe C:\downloads\strings	est.txt 1
Exception EFOpenError in module reader.exe at 0000FFF5.
Cannot open file C:\downloads\strings	est.txt.

Thats what I see in the console when I try it. I tried using both reletive and absolute paths for the input file.

I am using Windoze XP with all the newest updates.

Any ideas?

BTW, thank you VERY much for helping me out here. I wont forget it.

dante

I found the problem. Apparently, you can only use a file named ‘text.txt’ as an input file. That should help a little if you plan on debuging.

Thanks again!

dante

One more thing: Would it be possible to add a param that would check the input file and output how many lines it has?

Thanks

dante

PS. Anyone know how to redirect input for the del command? I have tried piping it like so:

reader %path% ext.txt 1 | del

But this returns an error saying the syntax of the cmd was incorrect…

thanks

ok dante, i fixed the file reading error, you should now be able to read any file.

also, i added the number of lines parameter, just type L.

for example, if text.txt reads as i described above, you could type:
reader.exe text.txt 3 L

this would return:

3.Lots and Lots of text 4

if you gave me a list of filenames that you need searched in a .txt file, i could use this to write a program that automatically does the moving for you (i think). but this may not be practical if you have a LOT of files.

tell me if it works!

Thanks for your hard work, man. When I was requesting that param, I meant that I wanted the prog to return JUST the max number of lines. Not the line AND the number of lines.

Does anyone know if its possible to set a variable equal to the output of a program? And a way to use the output of a program as input for the del command?

Thanks

dante