Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi
In my case i want to read a text file in such a way like that it will take the first line form the text and forward it to the vsstext is like
file name file path
A B
C dand i want to forward it as B/A for he first line and then it comes to second line to take the other path
After Path is seperated from file name by a SpaceBAR and other files by an enter
himanshu

Try to explain what you want to achieve in plain words and as exactly as possible.
English isn't my mothertongue, but your post is really cryptic.

i need a program which will take data from text file and in textfile i have data in this manner
file_name file_path
A B
C d
it means for first file file name is'A' file path is 'B'.
the program should read the text and give me output as 'B/A' which i need to use in my operation.Then it will read the next file and give me output as 'd/C' this process is repeated till all the files are processedPlease tell if you do it because i have very little knowledge about batch files but i need to make this program for my operation
himanshu

@Echo Off> fileout.txt
For /F "tokens=1-2" %%a in (filein.txt) Do (
Echo.%%b/%%a>> fileout.txt)This works if file_name and file_path have no embedded spaces. If the first line is the header replace "tokens=1-2" with "skip=1 tokens=1-2".
Let me know if what posted works. I'll be back 1 hour later.

hi
Thanks a lot it is coming but can i redirect this output i.e. in fileout.Because i need this output 'b/a' in vss command so that i can locate this files in vss server
Its command is ss checkout b/a..i want this b/a from fileout.txt
Please tell me if you can do this
himanshu

Please, first confirm me the pathname/filename output from my script is correct (no spaces in path/file), then explain what you mean by "vss command format" as this notation is unknown to me.
Do you want each output path/file line be executed as a command statement while the text file is read or stored in executable format in an output file for a later process?
In both cases specify the exact format of the command line that embeds the path/file data.
Otherwise tell me what you want as output.

hi
see yes your script was right it is giving right output.I have to automate some part of visual source safe for that i need path/file as input in command "ss checkout <path/file>".
Now what ever output we are getting i have to redirect it to the above command.
himanshu

@Echo Off
Echo.@Echo Off > ssexec.bat
For /F "tokens=1-2" %%a in (filein.txt) Do (
Echo.ss checkout %%b/%%a>> ssexec.bat)The above batch generates the ssexec.bat holding on each line the command
ss checkout path/file (from the filein.txt)
You can start the ssexec script by typing at prompt
ssexec
after the first sript ends or you can add the above line at the end of the native script to trigger it automatically.
Please report if I have understood your wish.

Yes sir thanks a lot you have completly understood,now can you please tell me if i can take input from user,in the code you have taken filein.txt as input if i want to take input from user like in which file they have stored information
himanshu

Here is the interactive version of the script self-triggering the ssexec script (the filename must not embed blanks, otherwise a more complex script is needed)
@Echo Off
:LOOP
Echo. Please enter the file name to be processed.
Set FileIn=
Set /P FileIn=^>
If not exist %FileIn% (
Echo.File %FileIn% does not exist.
GoTo :LOOP
)
Echo.Reading %FileIn%
Echo.@Echo Off > ssexec.bat
For /F "tokens=1-2" %%a in (%FileIn%) Do (
Echo.ss checkout %%b/%%a>> ssexec.bat)call ssexec
Del ssexec.bat
Set FileIn=
:: End_Of_Batch

Hi that is fine but can you please tell me why you have written Set /P FileIn=^>"additional operators"after equal to sign.
see my dos path is C:/program files/mvssand my files are in c:/test/<filename>
If not exist c:/test/%FileIn%.txt(
Echo.File %FileIn% does not exist.
GoTo :LOOPthen it is giving syntax error
himanshu

First the ^> symbol.
the Set /P syntax states
Set /P <var_name>=[string]
where string is an optional message to be displayed in front of the cursor waiting for user's input. So ^> mimics the raw prompt showing the script is waiting for input.
If you want to replicate the NT (NOT DOS) prompt you have to codeSet /P FileIn=%CD%^>
but now you can't say if the prompt is issued by the script or OS.
The error you get is due to the lack of space between %FileIn%.txt and the left parenthesis (.

hi now its working.Well i dont whether it will be complicated or not
but right now i am getting output as
ss checkout b/a
ss checkout d/ccan i get output as ss checkout b/a d/c f/e soo on.
himanshu

Technically yes, but actually that is not reccommanded as the command line has a limit of 127 chars and the variable to be set up for the purpose may even exceed reasonable size.
Maybe the ss command allows a parameter to read directly from a file but I don't know its syntax; you may try ss /? to display an on-line help.

If i dont bother about the limit of 127 char then can we do anything like that.See first output should be like "a/b d/f/ e/f" and so on..donot take ss into consideration then this output can be used to run "ss checkout a/b d/f/ e/f"
if you can do this then that will be better
himanshu

The following script works as you wish; it stacks into the variable "tail" the processed output from the input file.
Then you can run directly ss checkout using "tail" as parameter or have the variable stored into the sstail.txt file holding just one long line.
To store a whole file into one variable is anyway a risky behavior that may cause unpredictable results.
@Echo Off
SetLocal EnableDelayedExpansion:LOOP
Echo.Please enter the file name to be processed.
Set FileIn=
Set /P FileIn=^>
If not exist %FileIn% (
Echo.File %FileIn% does not exist.
GoTo :LOOP)Echo.Reading %FileIn%
Set tail=
For /F "tokens=1-2" %%a in (%FileIn%) Do (
Set tail=!tail! %%b/%%a)Echo.%tail%> sstail.txt
ss checkout %tail%
:: End_Of_Batch

hi
can you tell how can we get a particular word from the text which is there in first line of the text
e.g
qwerty
asdfgh
cvbnthis is the text and i need only word 'r' from the first linerest i dont need .Can we do that?
himanshu

Do you want to extract a particular word from the first line of a text file (e.g.
my girl is a nice blondie CR/LF
extract girl)?
As in your post "r" is a character not a word.

hi that problem was solved but i realy need to solve this problem can we use if condition in for loop?if i cant use then how can we solve this problem.
@echo off
set a=
for /F "tokens=1,2*" %%i in (myfile.txt) do (
echo.%%j/%%i
echo.%%k
set a=%%k
if %a%==2 (echo yes) else (echo no)
)
it is giving error as
(echo was unexpected at this time
myfile.txt contain
a a 1
s d 2Output should be like
first it should give no then yes
himanshu

The error you get is due to the misuse of variables inside a compound statement, i.e. a statement requiring parenthesis to mark a "command sequence".
In that case the variable is expanded with the value it has BEFORE the sequence's begin and never changed, so you get nul for a at IF time.
To avoid that you have to enable the "delayed expansion" and then use dynamic variables marked by ! instead the usual %.
So your script becomes
@echo off
SetLocal EnableDelayedExpansionset a=
for /F "tokens=1,2*" %%i in (myfile.txt) do (
echo.%%j/%%i
echo.%%k
set a=%%k
if "!a!"=="2" (echo yes) else (echo no)
)and better always to embrace the variable with " when performing an IF statement.

Don't post in the DOS forum questions that have nothing to do with DOS: the script you are coding is NT batch interpreted by cmd.exe not command.com.
There is no DOS in Windows NT/2000/XP as they are NT kernel operating systems; what looks like the DOS prompt is NT console and the system just offers an emulator for legacy DOS applications, NTVDM aka NT Virtual DOS Machine.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |