1.

Solve : Reading from a data file in a batch file?

Answer»

Hi DOS People!

I am trying to learn to use batch files.
For starters - I would like to read a read a data file and just echo EVERY line back.

I found the following syntax in a help file somewhere, but it doesn't do anything.
The command seems to be ignored. I verified the filename and there are 5 lines of data.

Any help would be appreciated.

This is what I've tried so far!!! Thanx in advance!!!!!!!!
=============================================
Code: [Select]@echo on
:: Learning how to read in batch
for /F %i in (H:\AppDevCtr\DistAppl\DataFile.txt) do @echo %i
echo done
pause
exit:
When the FOR statement is used in a batch file, you need to double up on the % signs:

Code: [Select]@echo off
:: Learning how to read in batch
for /F "tokens=1*" %%i in (H:\AppDevCtr\DistAppl\DataFile.txt) do echo %%i
echo done
pause

I would be very hesitant about using scripts from the web unless you're very sure they won't damage your machine.

8-)
OBVIOUSLY a good DAY! Your solution worked like a charm.

Would you be so kind as to give me a run down or different variable types? I didn't know there was such a thing as %%.

Also, you could you direct me towards some good documentation on using batch files. I am a Microsoft Access programmer by profession. I used to use REXX to do batch type stuff when I was working in other environments. I know they have REXX for PCs but I'm trying to work with what is readily available (and free) first - so I'm using .bat.

Finally, I just thought I'd let you know that I used the info you gave me to give me the ability to use XCOPY to copy a LIST of files specified in another file. Sounds like a little thing, but it will help me a bunch and give me something to expand on.

Thanx a meg

Code: [Select]@echo off
:: ----------------------------------------------------------------------------------------------------
:: I cannot FIND a way to XCOPY specifying the destination filename w/o being prompted
:: " Is destination a file or directory.
:: For now, I will just keep the file named the same thing and copy it to
:: a different directgory. This is a limitation I need to overcome.
:: ----------------------------------------------------------------------------------------------------


for /F "tokens=1,2*" %%i in (H:\AppDevCtr\DistAppl\DataFile.txt) do xcopy %%i %%j /y /q /k /d /u

echo You are done! ------------ but we have to get rid of that nagging file or directory message
echo @errorlevel

pause
exit:
You didn't mention which you wanted, the D or the F. Make changes accordingly:

Code: [Select]@echo off
:: ----------------------------------------------------------------------------------------------------
:: I cannot find a way to XCOPY specifying the destination filename w/o being prompted
:: " Is destination a file or directory.
:: For now, I will just keep the file named the same thing and copy it to
:: a different directgory. This is a limitation I need to overcome.
:: ----------------------------------------------------------------------------------------------------


for /F "tokens=1,2*" %%i in (H:\AppDevCtr\DistAppl\DataFile.txt) do echo [highlight]d[/highlight] | xcopy %%i %%j /y /q /k /d /u

echo You are done! ------------ but we have to get rid of that nagging file or directory message
echo @errorlevel

pause

I keep removing the exit: it has no meaning as written; use either :exit or just the word exit.

For batch help either Allenware or Rob Vanderwoude can be very helpful.

You already have VBScript and JScript installed (you have Windows, yes?) and they offer much more functionality than batch code.

REXX is now available free for PC's so you could leverage your knowledge and forget the learning curve. I learned REXX on an IBM VM/CMS machine and still use it on this PC. Great language and easier to learn and use than batch.

8-)What a coincidence. I also learned REXX and EXECIO on VM/CMS. I then used it on MVS/TSO.

I will certainly see if I can get a free copy of PC Rexx - Could you tell me where to go for a free copy of Rexx?
What text editor do you use with REXX? Do you know if there is ONE that allows file comparisons?

Practically speaking, it sounds like VBScript or JScript may be that replacement for BATCH files since it is already a part of Windows XP. I use Windows XP and if I do work on someone elses computer, I would have to install REXX to use it. Are there any significant PROs/CONs of VBScript vs. JScript. I already know VBA for Access so I'm thinking VBScript might be the way to go.

Thanx a gazillioin![size=14][/size] I appreciate the help!

AngeloIBM Object Rexx was recently released to open source: Object REXX . The IDE was not. You can run your Classic Rexx scripts under the Object Rexx interpreter.

Personally I use Texturizer as my editor although I had to write my own syntax highlighting file for the REXX language. I also use SPF/PC ($) which apparently has not been updated since WinNT and could not find a live link. There is a free editor modeled after XEDIT called THE.

Many editors SUPPORT macros which is a great way to extend their functionality (ex. file comparisons). IBM is great for that as the macro language is REXX.

The easiest thing would be to leverage your knowledge of VBA and use VBScript. For whatever reason, most of the examples on the Script Center site use VBScript and not JScript.

Regards. 8-)



Discussion

No Comment Found