pookeeshtron
pookeeshtron

Reputation: 135

Enviromental variables into text file

How do I write enviromental variables into text file with my name? My code is like:

@echo off
cd c:\users\user\desktop\
set /p name = "Input filename: "
copy nul %name%.txt
set > %name%.txt

But it doesn't create any file.

Upvotes: 0

Views: 47

Answers (1)

paxdiablo
paxdiablo

Reputation: 882206

Your problem lies with:

set /p name = "Input filename: "

The space immediately following the name will actually create a variable name called name<space>, which you will be able to see if you execute set nam to show all variables starting with that value.

See the following transcript for proof:

C:\pax> set /p x = ?
?with-space

C:\pax> set /p x=?
?no-space

C:\pax> set x
x=no-space
x =with-space

That transcript also shows how to fix it, simply change your line to remove the spaces:

set /p name="Input filename: "

Upvotes: 1

Related Questions