Computing.Net > Forums > Programming > Batch File|Input from txt file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch File|Input from txt file

Reply to Message Icon

Name: meil_karade_rabba
Date: November 23, 2008 at 21:27:17 Pacific
OS: XP
CPU/Ram: 1 GB
Product: Intel
Comment:

I have seen many posts and they helped me alot, still I am facing a basic issue.
I am working on Win XP.

I need a to create a batch file which takes inputs from a txt file, say

var1_address = D:\abc\some_address
var2_address = D:\xyz\some_address
var3_address = machine_name\path
var4_address = another_machine_name_path\some address

I want to take input from any of these paths and perfome below tasks

Ren var1_address *.zip

del var3_address\filename.zip

Problem:
1. I am unable to take all different addresses.
2. If I am able to take different inputs then I am unable to perform rename, delete kinda operations.


Please help me ASAP.

Thanks
Sunny



Sponsored Link
Ads by Google

Response Number 1
Name: BatchFreak
Date: November 23, 2008 at 21:45:02 Pacific
Reply:

Im not certain I follow.... I will try to help if you explain... Are the Commands stored in the Files? Or are you trying to perfom multiple tasks to different files, based on file name.... Please bear with me, I am a horrible communicator, especially when its through text.

I only Batch if possible, 2000 more lines of code, oh well.


0

Response Number 2
Name: meil_karade_rabba
Date: November 23, 2008 at 22:19:23 Pacific
Reply:

Its ok.
Thanks for giving your time.

Actually, I will write my commands in 1 batch file and take input of the path names from a txt file.

For example,
I will take remote machine name of server1 from text file name's variable "variable1" and perform command "ren variable1\*.* *.zip"

So path only includes folder name that could be of a remote machine or local drive.

Am I able to understand my problem in better manner?


0

Response Number 3
Name: Mechanix2Go
Date: November 23, 2008 at 23:43:53 Pacific
Reply:

[1 If you want to set vars you need to use SET. [surprise]

[2] If you want to set var1 using the contents of one.txt:

set /p var1=<one.txt

[3] That will set var1 to the FIRST line of one.txt.

[4] You will want to be very careful with spaces in your SET because things can get very messy, very fast.


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 4
Name: meil_karade_rabba
Date: November 24, 2008 at 00:13:00 Pacific
Reply:

this will set to the 1st line only
what if I have data in following format of txt file :
var1_address = D:\abc\some_address
var2_address = D:\xyz\some_address
var3_address = machine_name\path
var4_address = another_machine_name_path\some address

Now how will I get each variable in batch file to be used in commands?
Plz help


0

Response Number 5
Name: Mechanix2Go
Date: November 24, 2008 at 00:21:37 Pacific
Reply:

The last line is just to show wht was done.


===========================================
@echo off & setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in (my.txt) do (
set %%a
)

set v


=====================================
If at first you don't succeed, you're about average.

M2


0

Related Posts

See More



Response Number 6
Name: meil_karade_rabba
Date: November 24, 2008 at 02:32:17 Pacific
Reply:

Environment variable testing_location not defined
Environment variable v not defined

These are the errors I am receving.

testing_location is the variable name.
testing_location = \\machine_name\folder_name

Sorry I am bothering you guys alot.


0

Response Number 7
Name: Mechanix2Go
Date: November 24, 2008 at 03:01:35 Pacific
Reply:

It might help if we had identical my.txt files.

Here's what's in mine.


====================================
var1_address=D:\abc\some_address
var2_address=D:\xyz\some_address
var3_address=machine_name\path
var4_address=another_machine_name_path\some


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 8
Name: meil_karade_rabba
Date: November 24, 2008 at 19:32:43 Pacific
Reply:

Its not working for me...

throwing following error message
" Environment variable v not defined
v "

what could the issue?



0

Response Number 9
Name: Mechanix2Go
Date: November 24, 2008 at 21:17:56 Pacific
Reply:

Like I said if we use the same text file and the same batch, we ight be able to troubleshoot it.


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 10
Name: meil_karade_rabba
Date: November 25, 2008 at 01:49:42 Pacific
Reply:

Cool
I am able to get values BUT
I cant rename the file.

What I mean, if
v = D:\abc\qwerty.txt
now i want to rename it to qwerty.zip

ren v qwerty.zip
ren &v% qwerty.zip

nothing is working out.
I am not too much champ in batch files.
Sorry if I am doing anything silly.

Please look into this small thing.


0

Response Number 11
Name: Mechanix2Go
Date: November 25, 2008 at 03:08:47 Pacific
Reply:

Assuming that you start your batch with:

@echo off
setLocal EnableDelayedExpansion

And you have set a var named V to D:\abc\qwerty.txt

And you now want to USE the var to rename a file, try this:

ren !v!\qwerty.txt qwerty.zip


=====================================
If at first you don't succeed, you're about average.

M2


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch File|Input from txt file

Extracting data out from txt file www.computing.net/answers/programming/extracting-data-out-from-txt-file-/20329.html

batch file to take input from .txt www.computing.net/answers/programming/batch-file-to-take-input-from-txt/18000.html

Batch pull Variable from TXT or CSV www.computing.net/answers/programming/batch-pull-variable-from-txt-or-csv/16094.html