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

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.

parsing a variable as a filename

Reply to Message Icon

Name: spoonman184
Date: April 1, 2008 at 03:33:24 Pacific
OS: Windows Vista
CPU/Ram: AMD X2 4400+ 2 GB DD
Product: 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...



Sponsored Link
Ads by Google

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

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...


0

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

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


0

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

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...


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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


Sponsored links

Ads by Google


Results for: parsing a variable as a filename

Upgrade or buy a new computer? www.computing.net/answers/windows-vista/upgrade-or-buy-a-new-computer/299.html

No options in media player, gone? www.computing.net/answers/windows-vista/no-options-in-media-player-gone/1020.html

Ordering a 64-bit DVD using OEM key www.computing.net/answers/windows-vista/ordering-a-64bit-dvd-using-oem-key/1498.html