::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?
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?
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…
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.
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.
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.
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?