Link to home
Start Free TrialLog in
Avatar of Luis Diaz
Luis DiazFlag for Colombia

asked on

VB Script Bat: search file based on a string name and a root folder

Hello experts,

I am looking for a script (batch or vbscript) in which I should be able to report/

-strFileNameString: (string name of my file)
-strRootFolder in which is located the the file that I am searching.

The script should be able to search recursively based on the strRootFolder specified in the script and report in a log-search file which are the locations (full folder patch) in which is located the file.
The idea is to report a string name such as toto and the script should be able to report the various location of files which contains toto based on the RootFolder reported in a log-search file

Example of log-search file:

toto_3747475757.ppt is located at: C:\Temp
toto_56F.txt is located at: C:\Temp\ongoing


Thank you very much for your help.
Avatar of oBdA
oBdA

Well, in its easiest form, you don't even need a script:
dir /s /b "C:\Search\root\*toto*.*" >"SearchToto.log"

Open in new window

Or do you need more complex search patterns, or want the search root hard coded, or just double-click, or some such?
And if you want it as script, should the arguments be passed in the command line, be hard coded in the script, be queried for (note: no tab completion for the folder path, like in the command line)?
Avatar of Luis Diaz

ASKER

Thank you very much for this proposal.

I would like to specify within the script:
strRootFolder="C:\Search\root\"
strString="toto"
strLogSearch="201606031554_Log_Search.log" (datestamp will be at the beginning of Log_Search, sorry I didn't specify at the beginning but I think it is useful)

And when I double click 201606031554_Log_Search.Log should be generated  and report the various various files locations which contains the strString reported.

example of 201606031554_Log_Search.Log composition

201606031554>>>>toto_titi.xls found located at "C:\Search\root\folder1\temp\"
201606031555>>>>toto-tati.ppt found located at "C:\Search\root\folder1\"

End of the search >>>>201606031558
......

If the script didn't found anything it should also report:

Not files found with the reported string "toto" in the reported root folder "C:\Search\root\"
End of the search >>>>201606031554

Thank you again for your help.
SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you very much for this proposal. I was traveling, I will take the time to test it this week.
I am really sorry for the delay.

I tested your lastd proposal and it works perfectly.

I have just a smal remark. In order to properly read the log file is there a way to insert a "return to the line" when I have:

>>>>datestamp

User generated image
Or insert line break in order to make the difference between the first sentence Start and the path location reported by the script?

The idea is to have something like this:

User generated image
Thank you again for y our help.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Tested and it works perfectly!!!!!!

Thank you again for your help.