recent
أخبار ساخنة

Rename Files and Folders using Batch script


How to rename file in Batch?

To rename any file or folder using batch script, you have to make sure that the file or folder which you are going to change it name is not opened or used by another program. 


After that it is easy to rename it as the following steps:
1- Open the notepad or any other text editor.

2- Turn the echo command off by typing @echo off

3- Use the command line ren followed by the file or folder name you want to change it, then leave space and type the new file or folder name.

4- Save the command lines as .bat file.

5- Run the batch file.

After running the batch, the file that you want to be renamed will take the new name directly, provided that is not opened or used by other software as mentioned before.
However, if the filename after the command ren was misspelled, the command prompt will ” The system cannot find the file specified.” And the filename will not change or alternate to the new one.

Example1: Rename the file data.txt to data2.txt and the folder test to Test2 using batch script

To rename and change the filename data.txt to the new name data2.txt, the following batch code is used
@echo off
ren data.txt data2.txt
Pause
Also, to change the folder name test to the new folder name Test2 the following batch code is used
@echo off
ren test Test2.txt
Pause
Therefore, we can notice that there is no difference between files and folder when it comes to rename each of them. Just following the batch code script pattern in renaming files and folders, will lead to update filename or folder name to the new modified one.

Rename file or folder contain space in the name

One frequent question among a lot of batch users is; how to change filename or folder name with more than one world and containing space between them? The simple answer to this case, is to put filename or folder name between the Quotes Marks “ ” and apply the renaming batch code on them like this:
@echo off
Ren “New Folder” test
Pause
Here, the folder named New Folder changed to the new folder name test. Hence, the compound filename or folder name, that include space, must be surrounded with the quotes “ ” in order to be recalled completely, when applying batch script on it.
author-img
العلم للجميع

تعليقات

ليست هناك تعليقات
إرسال تعليق
    google-playkhamsatmostaqltradent