some questions
Moderator: DosItHelp
some questions
i have some questions hope i can find a answer on here
1-fist is there any good quide about for command?
2-what is diffrence between label and a function in batch?
for exmaple
@echo off
echo welcome
goto label1
:label
echo test
:label1
echo test 2
exit
this is label or a function?i think there is no diffrence but i am not sure about it!
1-fist is there any good quide about for command?
2-what is diffrence between label and a function in batch?
for exmaple
@echo off
echo welcome
goto label1
:label
echo test
:label1
echo test 2
exit
this is label or a function?i think there is no diffrence but i am not sure about it!
Re: some questions
A label is a line that start in colon, like this one:
A label serves as the target destination for two commands: GOTO and CALL. If a GOTO is used, it just transfer the execution to the destination line:
If a CALL :LABEL is used, then all the following happens:
In previous example, note that if GOTO :EOF command were omitted, after "Third line" were printed, "Second line" would be printed again. This is usually an error, so:
Note that the same label may be used both as a function (destination for CALL) and as a "simple label" (destination for GOTO), but this is not usual.
Code: Select all
:label
A label serves as the target destination for two commands: GOTO and CALL. If a GOTO is used, it just transfer the execution to the destination line:
Code: Select all
echo First line
goto label
note that this point can NEVER be reached
so another label should ALWAYS follows a GOTO command
. . .
:label
echo Second line
If a CALL :LABEL is used, then all the following happens:
- The destination label is named a "subroutine" (or "function" if you prefer)
- The lines following the label are executed
- The subroutine must ALWAYS end in a EXIT /B or GOTO :EOF command! At this point, the execution is transfered back to the line that follows the CALL :LABEL command
Code: Select all
echo First line
call :label
echo Third line
goto :EOF
:label
echo Second line
exit /B
In previous example, note that if GOTO :EOF command were omitted, after "Third line" were printed, "Second line" would be printed again. This is usually an error, so:
- Before the label that start a subroutine, a GOTO :EOF or EXIT /B command must ALWAYS be included!
Note that the same label may be used both as a function (destination for CALL) and as a "simple label" (destination for GOTO), but this is not usual.
Re: some questions
wow tnx
does anyone have a guide about for command?
does anyone have a guide about for command?
Re: some questions
For the basics you could look at http://ss64.com/nt/for.html.
The site describes the most internal and external batch commands.
It's a good starting point.
jeb
The site describes the most internal and external batch commands.
It's a good starting point.
jeb
-
- Posts: 240
- Joined: 04 Mar 2014 11:14
- Location: germany
Re: some questions
if you in a call - with Parameter %0 you can check this
Phil
Code: Select all
:Sub
rem if not in Sub than not Exit
if "%~0" equ ":Sub" Exit /b
Phil
Re: some questions
tcpman wrote:wow tnx
does anyone have a guide about for command?
Open up a command prompt and type: for /?
Re: some questions
tnx but i use the cmd for help and that site but still could not understand
for exmaple why this is not working?
for/l %%a in (1,1,10) do rename %%a
i make a batch file in a folder and then i run it it but its not renaming the files on that folder
what part of my code is need to get fixed?
and about functions is this one a function?
@echo off
echo going to function
call:function
echo ...
:function
echo function test
goto:EOF
but why the echo ... is not working?
for exmaple why this is not working?
for/l %%a in (1,1,10) do rename %%a
i make a batch file in a folder and then i run it it but its not renaming the files on that folder
what part of my code is need to get fixed?
and about functions is this one a function?
@echo off
echo going to function
call:function
echo ...
:function
echo function test
goto:EOF
but why the echo ... is not working?
Re: some questions
tcpman wrote:for exmaple why this is not working?
for/l %%a in (1,1,10) do rename %%a
That is using a for-in-do command and a rename command.
The rename command is not right.
Look at the help for the rename command.
If you describe what you are trying to do then we can describe or show you how to do it.
Re: some questions
oh yes sory
for /l %%a in (1,1,10) do rename c:\prodata\*.txt %%a.txt
ok
so for exmaple i want the files in prodara folder be something like this
before runing for command
text.txt
erer.txt
etet.txt
after runing for command
1.txt
2.txt
3.txt
for /l %%a in (1,1,10) do rename c:\prodata\*.txt %%a.txt
ok
so for exmaple i want the files in prodara folder be something like this
before runing for command
text.txt
erer.txt
etet.txt
after runing for command
1.txt
2.txt
3.txt
Re: some questions
tcpman wrote:oh yes sory
for /l %%a in (1,1,10) do rename c:\prodata\*.txt %%a.txt
ok
so for exmaple i want the files in prodara folder be something like this
before runing for command
text.txt
erer.txt
etet.txt
after runing for command
1.txt
2.txt
3.txt
You can't do it with a simple for /L command but a regular for command can list the files
for %%a in (*.txt) do echo "%%a"
and you will need a counter variable that increments the number for each filename.
The regular for command needs some extra handling when you are altering the filenames with the same filespec of *.txt because of a bug.
It's not very useful giving an example to change filenames to 1.txt 2.txt 3.txt ect because that is unlikely to be what you need to do,
and batch files can change markedly when the task details change.
If you describe the actual task then it is easier to provide some sample code.
Re: some questions
i just want to learn the for command
ok i think asking for this exmaple is better
ok how we can make a input and then if it was DOSTIPES
turn that to dostips
case sentence!
i saw a exmaple on that but culdnt understand it
and can you answer the function question?
ok i think asking for this exmaple is better
ok how we can make a input and then if it was DOSTIPES
turn that to dostips
case sentence!
i saw a exmaple on that but culdnt understand it
and can you answer the function question?
Re: some questions
There are many ways to do a task - and the exact requirements will eliminate some ways and promote other ways.
Here is a way to do your task:
If you post your function code then your question may be clearer. Earlier you said that 'echo' wasn't working and I don't see why.
Here is a way to do your task:
Code: Select all
@echo off
set /p "char=Enter uppercase text: "
type nul > "%char%"
dir /b /l "%char%" >temp.tmp
set /p "var="<temp.tmp
echo Input was "%char%" and is now "%var%"
del temp.tmp "%char%"
pause
If you post your function code then your question may be clearer. Earlier you said that 'echo' wasn't working and I don't see why.
Re: some questions
this is my code
the output is
going to function
function test
now i think the output must be
going to function
...
function test
Code: Select all
@echo off
echo going to function
call:function
echo ...
:function
echo function test
goto:EOF
the output is
going to function
function test
now i think the output must be
going to function
...
function test
Re: some questions
Where you have a blank line in your function code, put this there
Does that fix it for you?
Code: Select all
goto :EOF
Does that fix it for you?
Re: some questions
yes tnx
its now work well
Code: Select all
@echo off
echo going to function
call:function
echo ...
:function
echo function test
PAUSE
goto :EOF
its now work well