Computing.Net > Forums > Windows Vista > parsing a variable as a filename

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

parsing a variable as a filename

Reply to Message Icon

Original Message
Name: spoonman184
Date: April 1, 2008 at 03:33:24 Pacific
Subject: parsing a variable as a filename
OS: Windows Vista
CPU/Ram: AMD X2 4400+ 2 GB DD
Model/Manufacturer: ACER
Comment:

What I would like to do is be able to take a variable with spaces in it and make a file with the name of the variable, as such:

set /p address=Enter the address:
Echo. >> %address%.txt

All it does is copy the first word of
%address% to the filename. I was wondering if you could take out the spaces within the variable, and then maybe do as the following:

Echo. >> "%word1% %word2%.txt"

I would also like this in batch only if possible.

crappy OEM comptuers...


Report Offensive Message For Removal


Response Number 1
Name: spoonman184
Date: April 1, 2008 at 11:31:10 Pacific
Reply: (edit)

EDIT: Got it to work.
echo. >> "%address%".txt

Then if you want it in a different directory, first cd to the directory of the folder "%address%".txt is located.
copy "%address%".txt "your\new\location"

crappy OEM comptuers...


Report Offensive Follow Up For Removal

Response Number 2
Name: smorgasbord
Date: April 1, 2008 at 11:33:55 Pacific
Reply: (edit)

This can be done using Visual Basic scripting:

1.Create a batch file with the following line:
wscript string.vbs

2.Create a new txt file:
string.txt

3.Rename string.txt to string.vbs

4.Enter the following lines in the vbs file:

Dim x
Dim s
x=inputbox("enter address:")
s = replace(x," ","")
x=s+".txt"
Msgbox(x)

5. Execute the batch file:
x will be the filename adress.txt

If you enter 'my new documents' when prompted for address:
x will be mynewdocuments.txt


Report Offensive Follow Up For Removal

Response Number 3
Name: spoonman184
Date: April 1, 2008 at 12:44:54 Pacific
Reply: (edit)

Well I originally thought I couldn't get spaces within a filename, so then I wanted to try getting rid of the spaces.
Also, Visual Basic is a lil confusing to me XP

crappy OEM comptuers...


Report Offensive Follow Up For Removal







Post Locked

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


Go to Windows Vista Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software