Search

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Velpreso
Posts: 18
Joined: 28 Dec 2012 10:03

Search

#1 Post by Velpreso » 28 Dec 2012 10:16

Hi everybody, i am new and i'm from Poland so sorry for my language and spelling mistakes. Can you talk how to do .bat with searching function. This batch must search folders or files for example if i write Test.txt it will find track C:\Users\user\Desktop\Test.txt Do you know how to build it ?

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Search

#2 Post by Squashman » 28 Dec 2012 10:23

Code: Select all

C:\>dir /a-d /b /s test.txt
C:\Users\Squash\Desktop\Test.txt

C:\>

Velpreso
Posts: 18
Joined: 28 Dec 2012 10:03

Re: Search

#3 Post by Velpreso » 28 Dec 2012 11:16

Doesn't work as i want :(

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Search

#4 Post by Squashman » 28 Dec 2012 11:43

Velpreso wrote:Doesn't work as i want :(

Your comment really isn't useful to solving your problem. If something isn't working the way you want it too then you probably didn't explain what you wanted clearly enough.

Velpreso
Posts: 18
Joined: 28 Dec 2012 10:03

Re: Search

#5 Post by Velpreso » 29 Dec 2012 04:16

I look for script who will find source code when i write test.txt it will search hard drive and show me source code to this file.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Search

#6 Post by foxidrive » 29 Dec 2012 04:30

Velpreso wrote:I look for script who will find source code when i write test.txt it will search hard drive and show me source code to this file.


You need to be exact in your explanation to get a batch file that is appropriate.

I think you are saying that you want a batch file called search.bat and you want to type

search test.txt

and it will search drive c: and open the file test.txt in notepad. Is that right?

Velpreso
Posts: 18
Joined: 28 Dec 2012 10:03

Re: Search

#7 Post by Velpreso » 29 Dec 2012 06:14

No :P. FOR EXAMPLE if i write test.txt in .bat it will be look for test.txt in hard drive and if find test.txt it will show me that test.txt was saved in C:\user\deskop or for example in D:\Downloads. In my view it should be build with function FOR.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Search

#8 Post by foxidrive » 29 Dec 2012 06:36

Squashman gave you the code that does that.

Here it is in a batch file - call it search.bat and then type

search test.txt

Code: Select all

@echo off
searching for "%~1"
dir /a-d /b /s "c:\%~1" "d:\%~1"
pause

Velpreso
Posts: 18
Joined: 28 Dec 2012 10:03

Re: Search

#9 Post by Velpreso » 29 Dec 2012 11:39

Thanks guys.

Post Reply