• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

parameter as a Filename

I am trying to pass a paramater as a file name something to the effect of

Set name = %1
echo 2> C:\ %name%_Finished.txt

The expected resukts should be

Does anyone know how I would go about acomplishing?
  • 2
1 Solution
Just remove the extra spaces and the 2 from the second line (2> is used to redirect errors to a file rather than standard output).  Change echo to echo. to echo a single blank line.  It's also usually a good idea to enclose the file path in quotes in case it contains a space.

Set name=%1
echo. > "C:\%name%_Finished.txt"

Open in new window

Also if your parameter might have quotes around it then you should use %~1 to remove them.

Here are some useful references:

set name=%~1
echo. > "C:\%name%_Finished.txt"

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now