- Rename file from command line [CMD]
- Errors:
- переименовать rename
- Синтаксис Syntax
- Параметры Parameters
- Комментарии Remarks
- Примеры Examples
- Переименование файлов и папок через командную строку Windows
- ren ren
- Синтаксис Syntax
- Параметры Parameters
- Комментарии Remarks
- Примеры Examples
- How to rename files in Windows CMD (command prompt)
- 2 Answers 2
Rename file from command line [CMD]
We can use the command rename to rename files from windows command prompt(CMD). Find below syntax of the command with examples.
Syntax of rename command:
After executing the above command we’ll have file2.doc in the folder d:\data
Ren is alias for rename , so both refer to the same command.
Errors:
- If the files is being used by a program, then rename command fails with below error.
- You also need to have sufficient privileges to rename the file.
- Rename changes just the file name, it does not convert a file from one type to another. For example, if you rename a file from mp4 to mp3 extension, it does not change the file format. Renaming a doc file ‘mydocument.docx’ to ‘mydocument.pdf’ does not make the file readable in Acrobat Reader.
Does the command have to be executed in the root directory, or can it be done in a subdirectory that is in the root directory? Also, can a directory be renamed (EXAMPLE: renaming Dell.dir to Newname.dir)?
yes, you can run the command (for that matter, any other windows command) from any folder, it need not be root folder. And yes, ren works for directories too. There’s a separate post for this – http://www.windows-commandline.com/rename-directory-from-command-line/
this command gives repeating of filename when there are more then 40 files in the folders ?
any solution for renaming 100s of file .
i have
4299999940_M_harsha.png these type of files in several sub folders, with similar name structure(42 as first part of name, 40_M_harsha as last part of name.. in between 6digits(which may contain 42 and 40 also.in this example it has 999999))
i have to rename it as 99999..i.e, remove first and last part of file name which is common for all files in the subfolder
another examples:
4292345640_M_harsha.png -> 923456
4291424040_M_harsha.png -> 914240
could u please help
how do I rename a file by keeping the last 20 characters. I have random file names however the last 20 characters are what I want to keep. They are dates and a document ID.
filename too long cannot rename Please now setup new rename
I use, Batch Rename Files Tool. You can easily found hier BatchRenameFiles.org that allows you to quickly rename all the files in a specified directory.
Simple stuff. Been there and done that but I have a mess of files that contain a “%20” or several in the filename. I need help to sort this out. My REXX program has produced a batch file containing lines like these:
1.JPG” corn_escaLator.jpg
ren “CHOCO%
1.JPG” choco_Lady.jpg
ren “CAT%20
4.JPG” cat_wet_getting_bathed.jpg
ren “CAT%20
3.JPG” cat_burrito.jpg
ren “CAT%20
2.JPG” cat_bra.jpg
ren “CAT%20
1.JPG” cat_bite_nose.jpg
ren “BOOTY%
1.JPG” booty_cake.jpg
ren “BIRD%2
2.JPG” bird_watersLide.jpg
ren “BIRD%2
1.JPG” bird_mouth_dog.jpg
ren “BIG%20
1.JPG” big_mac.jpg
ren “BANK%2
1.JPG” bank_cake.jpg
ren “ANGEL%
Suffice to say it isn’t working as intended. I get tons of
“The system cannot find the file specified.” messages.
I prefer not to use the powershell whether I have it or not in case I need to run this in a more primitive Windows. I have tried rename instead of ren and without double quotes. I have administrator privileges.
I am running Windows7 32-bit.
GOOD, IT WORKED FOR ME
I use windows 10, and I did the steps, even in the location but it ‘couldn’t find the file specified.’ Please help.
переименовать rename
Область применения: Windows Server (половина ежегодного канала), Windows Server 2019, Windows Server 2016, Windows Server 2012 R2, Windows Server 2012 Applies to: Windows Server (Semi-Annual Channel), Windows Server 2019, Windows Server 2016, Windows Server 2012 R2, Windows Server 2012
Переименовывает файлы или каталоги. Renames files or directories.
Эта команда аналогична команде REN. This command is the same as the ren command.
Синтаксис Syntax
Параметры Parameters
Параметр Parameter | Описание Description |
---|---|
[ :][ |
]
Комментарии Remarks
При переименовании файлов нельзя указывать новый диск или путь. You can’t specify a new drive or path when renaming files. Эту команду также нельзя использовать для переименования файлов на дисках или для перемещения файлов в другой каталог. You also can’t use this command to rename files across drives or to move files to a different directory.
Символы, представленные подстановочными знаками в имя_файла2 , будут совпадать с соответствующими символами в имя_файла1. Characters represented by wildcard characters in filename2 will be identical to the corresponding characters in filename1.
Имя_файла2 должно быть уникальным именем файла. Filename2 must be a unique file name. Если параметр имя_файла2 совпадает с существующим именем файла, появляется следующее сообщение: Duplicate file name or file not found . If filename2 matches an existing file name, the following message appears: Duplicate file name or file not found .
Примеры Examples
Чтобы изменить все расширения имени файла txt в текущем каталоге на расширения DOC, введите: To change all the .txt file name extensions in the current directory to .doc extensions, type:
Чтобы изменить имя каталога с Chap10 на Part10, введите: To change the name of a directory from Chap10 to Part10, type:
Переименование файлов и папок через командную строку Windows
Хотя командная строка в Windows это далеко не такой же мощный инструмент по сравнению с терминалом в Linux, она обладает множеством базовых функций. Сегодня поговорим о переименовании файлов и каталогов.
За переименование файлов и папок в командной строке Windows отвечает команда RENAME. Можно использовать и укороченный вариант REN. Поскольку использовать укороченный вариант явно проще, в дальнейшем в этой статье будем использовать его.
Синтаксис команды ren очень прост для понимания:
REN [путь_к_файлу]\[текущее_имя_файла] [новое_имя_файла]
Если речь идёт о текущем каталоге, то достаточно команды
Эта команда переименует файл primer.txt в new_primer.txt.
Если речь идёт не о текущем каталоге, то требуется указать полный путь к файлу:
При указании нового имени нельзя задать другой каталог. Команда ren только даёт новое имя файлу, не перемещая его.
Аналогично можно переименовать и папку:
Обратите внимание, что наличие пробела заставляет нас использовать кавычки.
Команда ren допускает и работу с несколькими файлами. Но тут нужно сделать весомую оговорку — ren работает с файлами и папками, у которых одно местоположение. Что это значит на практике? Задать одно и то же имя нескольким файлам одновременно команда ren не позволит. Ведь местоположение этих файлов совпадает. В этом случае будет выведена ошибка «файл с таким именем уже существует или не найден». Причем первый по имени файл всё таки будет переименован.
А вот массово изменить расширение файлов команда ren способна. Для этого можно ввести команду вида
Это изменит всем файлам в текущем каталоге расширение с txt на doc.
Вот, пожалуй, и всё, что нужно знать о команде rename . Никаких параметров у этой команды нет.
ren ren
Область применения: Windows Server (половина ежегодного канала), Windows Server 2019, Windows Server 2016, Windows Server 2012 R2, Windows Server 2012 Applies to: Windows Server (Semi-Annual Channel), Windows Server 2019, Windows Server 2016, Windows Server 2012 R2, Windows Server 2012
Переименовывает файлы или каталоги. Renames files or directories.
Эта команда аналогична команде Rename. This command is the same as the rename command.
Синтаксис Syntax
Параметры Parameters
Параметр Parameter | Описание Description |
---|---|
[ :][ |
]
Комментарии Remarks
При переименовании файлов нельзя указывать новый диск или путь. You can’t specify a new drive or path when renaming files. Эту команду также нельзя использовать для переименования файлов на дисках или для перемещения файлов в другой каталог. You also can’t use this command to rename files across drives or to move files to a different directory.
Символы, представленные подстановочными знаками в имя_файла2 , будут совпадать с соответствующими символами в имя_файла1. Characters represented by wildcard characters in filename2 will be identical to the corresponding characters in filename1.
Имя_файла2 должно быть уникальным именем файла. Filename2 must be a unique file name. Если параметр имя_файла2 совпадает с существующим именем файла, появляется следующее сообщение: Duplicate file name or file not found . If filename2 matches an existing file name, the following message appears: Duplicate file name or file not found .
Примеры Examples
Чтобы изменить все расширения имени файла txt в текущем каталоге на расширения DOC, введите: To change all the .txt file name extensions in the current directory to .doc extensions, type:
Чтобы изменить имя каталога с Chap10 на Part10, введите: To change the name of a directory from Chap10 to Part10, type:
How to rename files in Windows CMD (command prompt)
Renaming files in Windows explorer is easy but when you need to rename many files it can become quite tedious. A command prompt (terminal) makes it easier.
2 Answers 2
Renaming 1 file in cmd is very easy:
In this example we have a sample1.txt and we want to change its name to sample2.txt :
Let’s say the filename is sample1-some-unwanted-text-1234.txt and we want to change it to sample1.txt :
Renaming 1 file by replacing multiple unwanted characters using a star:
Let’s say the filename is sample1-some-unwanted-text-1234.txt and we want to change it to sample1.txt without having to type the whole filename:
This * basically means any characters inbetween sample1 and .txt will be replaced.
Renaming multiple files with similar names
If you want to rename multiple files, i.e. sample1 2020-08-01.txt , sample2 2020-08-05.txt , sample3 2020-08-10.txt , sample4 2020-08-13.txt , you want to keep the first 7 characters you want to get rid of the dates:
In this example, you want to keep the word sample and the number X (where X can be any number or character). Using a ? will leave the number in place and * instructs the rename-command to replace any characters in between sampleX and .txt
Warning: It happens very quickly that a command prompt rename operation renames too many files and you can’t undo it. So, when renaming multiple files it is advisable to make a copy of all the files you want to rename, put them in a temp folder, then run your rename commands in the temp folder, and when you’re certain that it works, go back and rename the original files.