search file using bat (no user input)
Moderator: DosItHelp
search file using bat (no user input)
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...
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)
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)
Sorry, there is much too few information:
- A specific directory, or
- a specific directory and all its subdirectories, or
- all drives (improbable but not impossible).
- Is it the only other txt file in a specific directory, or
- is it defined by other specifications?
penpen
Where do you search:xhai wrote:i want to search for a file without user input..
- A specific directory, or
- a specific directory and all its subdirectories, or
- all drives (improbable but not impossible).
How do you know with which it is replaced:xhai wrote:What if i delete "1.txt" and replace it with any name with .txt extension the program will not work..
- Is it the only other txt file in a specific directory, or
- is it defined by other specifications?
If we know where to search, and for what we are searching then yes, else no.xhai wrote:is this possible auto detect if there is a new .txt and replace it to the set command
penpen
-
- Posts: 240
- Joined: 04 Mar 2014 11:14
- Location: germany
Re: search file using bat (no user input)
Within a for /f command you use
to Set the newest file into Var.
Then you can rename Var.
Phil
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)
pieh-ejdsch wrote:Within a for /f command you useCode: 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)
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)
The batch file you use, produces " .iso" on space input, and ".iso" on empty input.foxidrive wrote:(...)xhai wrote:the program accept blank or when i press enter without writing any data...
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)
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?