Solved

How to rename a file with CMD including the hostname?

Posted on 2015-01-28
3
84 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
RSOP Red "X" 7 45
Problems with Microsoft.DHCP.PowerShell.Admin Module 4 56
Group policy to delete files in folder 3 42
Unable to add new user to AD 2 24
Redirected folders in a windows domain can be quite useful for a number of reasons, one of them being that with redirected application data, you can give users more seamless experience when logging into different workstations.  For example, if a use…
A procedure for exporting installed hotfix details of remote computers using powershell
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…

832 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