# Script to rename files on Windows devices

Management of files becomes easier if they are named sensibly. Hexnode lets admins to rename files on multiple devices simultaneously using [scripts](https://www.hexnode.com/mobile-device-management/help/executing-custom-scripts-for-windows/).

 Note: 
**Supported Versions**:

The scripts given below will be supported on the following versions:

- Windows 10 v1607+ (Pro, Enterprise, Education)
- Windows 11 (Pro, Enterprise, Education)

[ ](https://developer.android.com/develop/connectivity/uwb#uwb-enabled_mobile_devices)

 

 Disclaimer:The Sample Scripts provided below are adapted from third-party Open-Source sites.

 

Batch Script
------------

Batch script to rename files on Windows

@echo off REM === Set the folder path and file names === set "TargetPath=C:\\Path\\To\\Your\\Folder" set "OldName=original\_filename.ext" set "NewName=new\_filename.ext" REM === Navigate to the target folder === cd /d "%TargetPath%" REM === Check if the file exists and rename === IF EXIST "%OldName%" ( ren "%OldName%" "%NewName%" echo File renamed successfully from "%OldName%" to "%NewName%" in "%TargetPath%". ) ELSE ( echo File "%OldName%" not found in "%TargetPath%". Rename failed. ) 

   1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

  @echo off 

REM === Set the folder path and file names ===

set "TargetPath=C:\\Path\\To\\Your\\Folder"

set "OldName=original\_filename.ext"

set "NewName=new\_filename.ext"

 REM === Navigate to the target folder ===

cd /d "%TargetPath%"

REM === Check if the file exists and rename ===

IF EXIST "%OldName%" (

 ren "%OldName%" "%NewName%"

 echo File renamed successfully from "%OldName%" to "%NewName%" in "%TargetPath%".

) ELSE (

 echo File "%OldName%" not found in "%TargetPath%". Rename failed.

) 

   

 

  

*set “TargetPath=C:\\Path\\To\\Your\\Folder”*

*set “OldName=original\_filename.ext”*

*set “NewName=new\_filename.ext”*

In the above command, replace the terms “C:\\Path\\To\\Your\\Folder”, “original\_filename.ext”, “new\_filename.ext” with actual path and names.

[![Script to rename files remotely executed successfully from Hexnode.](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2021/09/File-names-renamed-remotely-with-scripts-300x150.png)](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2021/09/File-names-renamed-remotely-with-scripts-300x150.png "File names renamed remotely with scripts")

PowerShell Script
-----------------

PowerShell script to rename files on Windows

rename-item "current\_filename\_with\_path.ext" "new\_filename\_with\_path.ext" 

   1

  rename-item "current\_filename\_with\_path.ext" "new\_filename\_with\_path.ext" 

   

 

  

E.g., To rename the file **test.txt** in the Desktop of the user Deborah to **testing.txt**,

*rename-item “C:\\Users\\Deborah\\Desktop\\test.txt” “C:\\Users\\Deborah\\Desktop\\testing.txt”*

 Notes:- Use quotes if the name has a space in between.
- It is recommended to manually validate the script execution on a system before executing the action in bulk.
- Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.