Solved

How to rename a file with CMD including the hostname?

Posted on 2015-01-28
3
81 Views
Last Modified: 2015-01-28
Using Batch I want to rename a file as follows

System.txt -> rename to -> system_server1.txt
0
Comment
Question by:acunaara
  • 2
3 Comments
 
LVL 95

Accepted Solution

by:
Lee W, MVP earned 500 total points
ID: 40575768
Very simple if by hostname you mean computer name:
Ren "system.txt" "%computername%_system.txt"
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 40575775
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"
0
 

Author Closing Comment

by:acunaara
ID: 40575795
Nice Thanks for your prompt response!!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Setting up a Microsoft WSUS update system is free relatively speaking if you have hard disk space and processor capacity.   However, WSUS can be a blessing and a curse. For example, there is nothing worse than approving updates and they just have…
On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
This tutorial will show how to push an installation of Backup Exec to an additional server in both 2012 and 2014 versions of the software. Click on the Backup Exec button in the upper left corner. From here, select Installation and Licensing, then I…
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now