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

How to rename a file with CMD including the hostname?

Using Batch I want to rename a file as follows

System.txt -> rename to -> system_server1.txt
  • 2
1 Solution
Lee W, MVPTechnology and Business Process AdvisorCommented:
Very simple if by hostname you mean computer name:
Ren "system.txt" "%computername%_system.txt"
Lee W, MVPTechnology and Business Process AdvisorCommented:
If you mean hostname (which in generally rare circumstances COULD be different from the computer name) then it's SLIGHTLY more complicated:
for /f %%a in ('hostname') do set Hostname=%%a
ren "system.txt" "%hostname%_system.txt"
acunaaraAuthor Commented:
Nice Thanks for your prompt response!!
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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