Page 1 of 1

search file using bat (no user input)

Posted: 09 Mar 2014 08:52
by xhai
Hi guys how do i code this in .bat?

i want to search for a file without user input..

after that do a command something like this...

set file = 1.txt
echo your file is %fie%

What if i delete "1.txt" and replace it with any name with .txt extension the program will not work..

is this possible auto detect if there is a new .txt and replace it to the set command

I hope you understand what i'm saying...

Re: search file using bat (no user input)

Posted: 09 Mar 2014 10:06
by foxidrive
I've checked a couple of your recent threads - and you should consider following up in the threads when people reply to you, just to say "thanks" or "it works" or something.

Re: search file using bat (no user input)

Posted: 09 Mar 2014 12:21
by penpen
Sorry, there is much too few information:
xhai wrote:i want to search for a file without user input..
Where do you search:
- A specific directory, or
- a specific directory and all its subdirectories, or
- all drives (improbable but not impossible).
xhai wrote:What if i delete "1.txt" and replace it with any name with .txt extension the program will not work..
How do you know with which it is replaced:
- Is it the only other txt file in a specific directory, or
- is it defined by other specifications?

xhai wrote:is this possible auto detect if there is a new .txt and replace it to the set command
If we know where to search, and for what we are searching then yes, else no.

penpen

Re: search file using bat (no user input)

Posted: 09 Mar 2014 14:18
by pieh-ejdsch
Within a for /f command you use

Code: Select all

dir /a-d /o-d *.txt

to Set the newest file into Var.
Then you can rename Var.

Phil

Re: search file using bat (no user input)

Posted: 11 Mar 2014 05:52
by xhai
pieh-ejdsch wrote:Within a for /f command you use

Code: Select all

dir /a-d /o-d *.txt

to Set the newest file into Var.
Then you can rename Var.

Phil


Thanks you Phil...
But how do code it in for /f loop it..

foxidrive wrote:I've checked a couple of your recent threads - and you should consider following up in the threads when people reply to you, just to say "thanks" or "it works" or something.


Sorry if i didn't say thanks.. all of them works now..
Thank you for the feedback and sorry again foxidrive next time i won't forget to say thanks..
do we have a thanks button?

penpen wrote:Where do you search:
- A specific directory, or
- a specific directory and all its subdirectories,
penpen


thanks penpen

Re: search file using bat (no user input)

Posted: 11 Mar 2014 19:38
by foxidrive
Please do not use PM's for personal support. Write your questions in the forum.


xhai wrote:the program accept blank or when i press enter without writing any data...

thank you and keep up foxidrive...

Code: Select all

:Start
cls
setlocal enableDelayedExpansion
color 07
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo ºThis supports only rip ISO format!                                º
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
echo.
echo Please enter the name of your ISO
echo.
color 03
set "ISO="
set /p "ISO="
for /F tokens^=1*^ delims^={}[]:/\^;^'^,~^`@#$%&^(^)+^=\/:*^?^"^<^>^| %%a in ("_!ISO!_") do if NOT "%%b" == "" goto :Start
if NOT "!ISO:*.iso=!" == "" set "ISO=!ISO!.iso"
if "%ISO%"=="" goto :Start
goto :Output

Re: search file using bat (no user input)

Posted: 12 Mar 2014 02:45
by penpen
foxidrive wrote:
xhai wrote:the program accept blank or when i press enter without writing any data...
(...)
The batch file you use, produces " .iso" on space input, and ".iso" on empty input.
Although unusual, both are valid file names, so there is no problem in accepting these inputs.
You may check it by creating them in the actual directory:

Code: Select all

> " .iso" echo(test
> ".iso" echo(test

penpen

Re: search file using bat (no user input)

Posted: 12 Mar 2014 06:41
by Squashman
xhai wrote:the program accept blank or when i press enter without writing any data...

thank you and keep up foxidrive...

Code: Select all

:Start
cls
setlocal enableDelayedExpansion
color 07
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo ºThis supports only rip ISO format!                                º
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
echo.
echo Please enter the name of your ISO
echo.
color 03
set "ISO="
set /p "ISO="
for /F tokens^=1*^ delims^={}[]:/\^;^'^,~^`@#$%&^(^)+^=\/:*^?^"^<^>^| %%a in ("_!ISO!_") do if NOT "%%b" == "" goto :Start
if NOT "!ISO:*.iso=!" == "" set "ISO=!ISO!.iso"
if "%ISO%"=="" goto :Start
goto :Output

What does this have to do with your original question?