You are not logged in.

#1 22 Dec 2015 01:07

Batcher
Member
Registered: 20 Jul 2015
Posts: 56

Create file named as environmental var

can I create file named as environmental variable the code I have below doesn't work

@echo on
title File Maker
if "%~1"=="/?" (
echo.
echo mk /f /d /? [File Name]
echo /f - create file
echo /d - create folder
echo file name the name of the file you wish to create.
goto x
)
if "%~1"=="/f" (
goto file
)
if "%~1"=="/d" (
goto directory
)
:file
if "%~2"=="" (
    set "name=%~2"
Echo. 2> %name%
exit /b
)
:directory
if "%~2"=="" (
    set "name=%~2"
md %name%
)
:x

thanks

Last edited by Batcher (22 Dec 2015 01:37)

Offline

#2 22 Dec 2015 03:07

Shadow Thief
Member
Registered: 12 Jul 2012
Posts: 205

Re: Create file named as environmental var

2>

will redirect anything that outputs to STDERR to a text file. Since echo doesn't throw an error when you use it, nothing is going to be sent. Use

1>

instead.

Offline

#3 22 Dec 2015 22:16

Batcher
Member
Registered: 20 Jul 2015
Posts: 56

Re: Create file named as environmental var

Shadow Thief wrote:
2>

will redirect anything that outputs to STDERR to a text file. Since echo doesn't throw an error when you use it, nothing is going to be sent. Use

1>

instead.

Shadow Theif this code is still unable to make a file with the name the user enters.

Offline

#4 22 Dec 2015 23:16

Batcher
Member
Registered: 20 Jul 2015
Posts: 56

Re: Create file named as environmental var

Never mind this works

set "name=%~1"
echo. 3> %name%
echo %name%
exit /b

Offline

Board footer

Powered by