Lost Password?


Go Back   CodeCall Programming Forum > Software Development > General Programming

General Programming Non language specific, Assembly, Linux/Unix, Mac and anything not covered in other topics. Talk about Programming Theory here.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-24-2008, 07:35 PM
aloishis89 aloishis89 is offline
Newbie
 
Join Date: Aug 2008
Posts: 2
Rep Power: 0
aloishis89 is on a distinguished road
Default batch command question

Hey, I was wondering if there is a way to use dos to read text files. i am writing a script that will open a text file from a flash drive and then read the contents (it will only be 1 word), and then store whatever is in there as a variable. I know that there also has to be a way to do it in bash, so if someone could help me out with either of those, that would be great.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 08-24-2008, 08:06 PM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 9,650
Last Blog:
PHP Objects, Patterns,...
Rep Power: 20
Jordan is just really niceJordan is just really niceJordan is just really niceJordan is just really nice
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default Re: batch command question

Try this:

Code:
@echo off
setlocal enabledelayedexpansion
set SEPARATOR=/
set filecontent=
for /f "delims=" %%a in ("YourFile.txt") do (
  set currentline=%%a
  set filecontent=!filecontent!%SEPARATOR%!currentline!
)
echo The file contents are: %filecontent%
In bash it would be easy:

Code:
someVariable=`cat <filename>`
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog
The CodeCall Wiki is now fully integrated with vBulletin users! Check it out and add some new pages!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-24-2008, 08:10 PM
aloishis89 aloishis89 is offline
Newbie
 
Join Date: Aug 2008
Posts: 2
Rep Power: 0
aloishis89 is on a distinguished road
Default Re: batch command question

When I put in the file name, it returns : The file contents are: /MyFile.txt
i have both files in the same directory and named correctly.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 08-27-2008, 07:51 PM
youwish youwish is offline
Newbie
 
Join Date: Aug 2008
Posts: 14
Rep Power: 0
youwish will become famous soon enough
Default Re: batch command question

Code:
@echo off
set file=xxx.txt
for /f "tokens=1*" %%a in (%file%) do echo %%a
pause
Is this what you want? My batch skills are rough.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Batch Programming Help InfiniteSpawn General Programming 11 08-20-2008 10:17 PM
Batch help-xcopy command arod General Programming 1 07-03-2008 07:20 AM
How to create a batch file in vb6 ? kresh7 Visual Basic Programming 3 12-23-2007 03:08 PM
Batch File Help ineedhelp General Programming 4 11-15-2007 08:04 PM
planning with batch file frysay General Programming 3 05-29-2007 04:59 AM


All times are GMT -5. The time now is 02:25 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads