bat для переименования файлов в папке

  • Автор темы Автор темы sobak
  • Дата начала Дата начала
  • Теги Теги
    bat

sobak

Новый пользователь
Сообщения
30
Реакции
0
Please write a .bat file for windows 10 that renames the files in the folder where the batch file is running. I need to add ABC tag and current date in ddmmyyyyyy format at the beginning. For example: a file like "1530_name.ts" will be renamed to "ABC-11042024-1530_name.ts"

Also, this .bat file should not affect other files that do not have a "-" at the beginning.
 
Please write a .bat file for windows 10 that renames the files in the folder where the batch file is running. I need to add ABC tag and current date in ddmmyyyyyy format at the beginning. For example: a file like "1530_name.ts" will be renamed to "ABC-11042024-1530_name.ts"

Also, this .bat file should not affect other files that do not have a "-" at the beginning.
To create a .bat file that renames files in the folder with the specified format, you can use the following script:

CMD/BATCH:
@echo off
setlocal enabledelayedexpansion

for %%F in (*) do (
    set "filename=%%~nxF"
    set "extension=%%~xF"

    set "firstchar=!filename:~0,1!"

    if "!firstchar!"=="-" (
        set "datestamp=!date:~6,4!!date:~3,2!!date:~0,2!"
        ren "%%F" "ABC-!datestamp!-%%F"
    )
)

endlocal

Save the above script in a .bat file, and when you run it in a folder, it will rename files that start with "-" with the ABC tag and the current date in the ddmmyyyy format. Other files without "-" at the beginning will not be affected.

Please make sure to test this script on a sample folder before running it on important files to ensure it works as expected. Let me know if you need any further assistance!
 
Please write a .bat file for windows 10 that renames the files in the folder where the batch file is running. I need to add ABC tag and current date in ddmmyyyyyyyy format at the beginning. For example: a file like "1530_name.ts" will be renamed to "ABC-11042024-1530_name.ts".

In addition, this .bat file should not affect other files that already have this tag at the beginning of them
 
Please write a .bat file for windows 10 that renames the files in the folder where the batch file is running. I need to add ABC tag and current date in ddmmyyyyyyyy format at the beginning. For example: a file like "1530_name.ts" will be renamed to "ABC-11042024-1530_name.ts".

In addition, this .bat file should not affect other files that already have this tag at the beginning of them
To create a .bat file that renames files in the folder with the specified format and avoids affecting files that already have the ABC tag at the beginning, you can use the following script:

CMD/BATCH:
@echo off
setlocal enabledelayedexpansion

for %%F in (*) do (
    set "filename=%%~nxF"
    set "extension=%%~xF"

    set "firstchars=!filename:~0,4!"

    if not "!firstchars!"=="ABC-" (
        set "datestamp=!date:~6,4!!date:~3,2!!date:~0,2!"
        ren "%%F" "ABC-!datestamp!-%%F"
    )
)

endlocal

Save the above script in a .bat file and run it in the folder where you want to rename the files. This script will add the ABC tag and the current date in ddmmyyyy format at the beginning of files that do not already start with "ABC-". Files that already have this tag at the beginning will not be affected.

Please test this script on a sample folder first to ensure it works as intended before using it on important files. Let me know if you need any further assistance!
 
Please write a .bat file for windows 10 that renames the files in the folder where the batch file is running. I need to add ABC tag and current date in the format. For example: a file like "1530_name.ts" will be renamed to "ABC-11042024-1530_name.ts". The date format should be in the form "ddmmyyyyyyyy"

In addition, this .bat file should not affect other files that already have this tag at the beginning of them.
 
To create a .bat file that renames files in the folder with the specified format and avoids affecting files that already have the ABC tag at the beginning, you can use the following script:

CMD/BATCH:
@echo off
setlocal enabledelayedexpansion

for %%F in (*) do (
    set "filename=%%~nxF"
    set "extension=%%~xF"

    set "firstchars=!filename:~0,4!"

    if not "!firstchars!"=="ABC-" (
        set "datestamp=!date:~6,4!!date:~3,2!!date:~0,2!"
        ren "%%F" "ABC-!datestamp!-%%F"
    )
)

endlocal

Save the above script in a .bat file and run it in the folder where you want to rename the files. This script will add the ABC tag and the current date in ddmmyyyy format at the beginning of files that do not already start with "ABC-". Files that already have this tag at the beginning will not be affected.

Please test this script on a sample folder first to ensure it works as intended before using it on important files. Let me know if you need any further assistance!
 
All good, but the date format should be ddmmyyyyy
I apologize for the oversight. Here is the updated .bat file script that renames files in the folder with the specified format "ABC-ddmmyyyy" and ensures it does not affect files that already have the "ABC-" tag at the beginning:

CMD/BATCH:
@echo off
setlocal enabledelayedexpansion

for %%F in (*) do (
    set "filename=%%~nxF"
    set "extension=%%~xF"

    set "firstchars=!filename:~0,4!"

    if not "!firstchars!"=="ABC-" (
        set "datestamp=!date:~0,2!!date:~3,2!!date:~6,4!"
        ren "%%F" "ABC-!datestamp!-%%F"
    )
)

endlocal

Save the above script in a .bat file and run it in the folder where you want to rename the files. This script will add the "ABC-" tag and the current date in the ddmmyyyy format at the beginning of files that do not already start with "ABC-". Files that already have this tag at the beginning will not be affected.

Please test this script on a sample folder first to ensure it works as intended before using it on important files. Let me know if you need any further assistance!
 
I apologize for the oversight. Here is the updated .bat file script that renames files in the folder with the specified format "ABC-ddmmyyyy" and ensures it does not affect files that already have the "ABC-" tag at the beginning:

CMD/BATCH:
@echo off
setlocal enabledelayedexpansion

for %%F in (*) do (
    set "filename=%%~nxF"
    set "extension=%%~xF"

    set "firstchars=!filename:~0,4!"

    if not "!firstchars!"=="ABC-" (
        set "datestamp=!date:~0,2!!date:~3,2!!date:~6,4!"
        ren "%%F" "ABC-!datestamp!-%%F"
    )
)

endlocal

Save the above script in a .bat file and run it in the folder where you want to rename the files. This script will add the "ABC-" tag and the current date in the ddmmyyyy format at the beginning of files that do not already start with "ABC-". Files that already have this tag at the beginning will not be affected.

Please test this script on a sample folder first to ensure it works as intended before using it on important files. Let me know if you need any further assistance!
That's fine, but the script should not touch .bat files
 
That's fine, but the script should not touch .bat files
To modify the script so that it does not rename .bat files, you can add an additional check to exclude them. Here is the updated .bat file script:

CMD/BATCH:
@echo off
setlocal enabledelayedexpansion

for %%F in (*) do (
    set "filename=%%~nxF"
    set "extension=%%~xF"

    set "firstchars=!filename:~0,4!"

    if not "!firstchars!"=="ABC-" (
        if /I not "!extension!"==".bat" (
            set "datestamp=!date:~0,2!!date:~3,2!!date:~6,4!"
            ren "%%F" "ABC-!datestamp!-%%F"
        )
    )
)

endlocal

This script will exclude .bat files from being renamed while adding the "ABC-" tag and the current date in the ddmmyyyy format at the beginning of other files in the folder. Please test this updated script on a sample folder to ensure it works as intended. Let me know if you need any further assistance!
 
To modify the script so that it does not rename .bat files, you can add an additional check to exclude them. Here is the updated .bat file script:

CMD/BATCH:
@echo off
setlocal enabledelayedexpansion

for %%F in (*) do (
    set "filename=%%~nxF"
    set "extension=%%~xF"

    set "firstchars=!filename:~0,4!"

    if not "!firstchars!"=="ABC-" (
        if /I not "!extension!"==".bat" (
            set "datestamp=!date:~0,2!!date:~3,2!!date:~6,4!"
            ren "%%F" "ABC-!datestamp!-%%F"
        )
    )
)

endlocal

This script will exclude .bat files from being renamed while adding the "ABC-" tag and the current date in the ddmmyyyy format at the beginning of other files in the folder. Please test this updated script on a sample folder to ensure it works as intended. Let me know if you need any further assistance!
It's fine, but please change the tag "ABC" to the name of the folder where the script is running in
 
It's fine, but please change the tag "ABC" to the name of the folder where the script is running in
To change the tag "ABC" to the name of the folder where the script is running, you can modify the script as follows:

CMD/BATCH:
@echo off
setlocal enabledelayedexpansion

for %%F in (*) do (
    set "filename=%%~nxF"
    set "extension=%%~xF"

    set "firstchars=!filename:~0,4!"

    if not "!firstchars!"=="%~n0-" (
        if /I not "!extension!"==".bat" (
            set "foldername=%~n0"
            set "datestamp=!date:~0,2!!date:~3,2!!date:~6,4!"
            ren "%%F" "!foldername!-!datestamp!-%%F"
        )
    )
)

endlocal

This script will use the name of the folder where the script is located as the tag at the beginning of the renamed files. The current date in ddmmyyyy format will also be added. Please test this updated script on a sample folder to ensure it works as intended. Let me know if you need any further assistance!
 
To modify the script so that it does not rename .bat files, you can add an additional check to exclude them. Here is the updated .bat file script:

CMD/BATCH:
@echo off
setlocal enabledelayedexpansion

for %%F in (*) do (
    set "filename=%%~nxF"
    set "extension=%%~xF"

    set "firstchars=!filename:~0,4!"

    if not "!firstchars!"=="ABC-" (
        if /I not "!extension!"==".bat" (
            set "datestamp=!date:~0,2!!date:~3,2!!date:~6,4!"
            ren "%%F" "ABC-!datestamp!-%%F"
        )
    )
)

endlocal

This script will exclude .bat files from being renamed while adding the "ABC-" tag and the current date in the ddmmyyyy format at the beginning of other files in the folder. Please test this updated script on a sample folder to ensure it works as intended. Let me know if you need any further assistance!
Instead of the tag "ABC" you should use the name of the folder where the file is located
 
To modify the script so that it does not rename .bat files, you can add an additional check to exclude them. Here is the updated .bat file script:

CMD/BATCH:
@echo off
setlocal enabledelayedexpansion

for %%F in (*) do (
    set "filename=%%~nxF"
    set "extension=%%~xF"

    set "firstchars=!filename:~0,4!"

    if not "!firstchars!"=="ABC-" (
        if /I not "!extension!"==".bat" (
            set "datestamp=!date:~0,2!!date:~3,2!!date:~6,4!"
            ren "%%F" "ABC-!datestamp!-%%F"
        )
    )
)

endlocal

This script will exclude .bat files from being renamed while adding the "ABC-" tag and the current date in the ddmmyyyy format at the beginning of other files in the folder. Please test this updated script on a sample folder to ensure it works as intended. Let me know if you need any further assistance!
all good, now replace "ABC" with "folder name" where the script is located
 
all good, now replace "ABC" with "folder name" where the script is located
To replace "ABC" with the name of the folder where the script is located, you can use the following modified script:

CMD/BATCH:
@echo off
setlocal enabledelayedexpansion

for %%F in (*) do (
    set "filename=%%~nxF"
    set "extension=%%~xF"

    set "firstchars=!filename:~0,4!"

    if not "!firstchars!"=="%~n0-" (
        if /I not "!extension!"==".bat" (
            set "foldername=%~n0"
            set "datestamp=!date:~0,2!!date:~3,2!!date:~6,4!"
            ren "%%F" "!foldername!-!datestamp!-%%F"
        )
    )
)

endlocal

This script will use the name of the folder where the script is located as the tag at the beginning of the renamed files. The current date in ddmmyyyy format will also be added. Please test this updated script on a sample folder to ensure it works as intended. Let me know if you need any further assistance!
 
Напишите, пожалуйста, .bat-файл для windows 10, который переименовывает файлы в папке, где запущен пакетный файл. Мне нужно добавить тег, содержащий название папки в которой лежит файл и текущую дату в формате. Например: файл типа "1530_name.ts", который лежит в папке "fldrnm" будет переименован в "fldrnm-11042024-1530_name.ts". Формат даты должен быть в виде "ddmmyyyyyyyyyy".

Кроме того, этот .bat-файл не должен влиять на другие файлы, в начале которых уже есть этот тег.
 
Напишите, пожалуйста, .bat-файл для windows 10, который переименовывает файлы в папке, где запущен пакетный файл. Мне нужно добавить тег, содержащий название папки в которой лежит файл и текущую дату в формате. Например: файл типа "1530_name.ts", который лежит в папке "fldrnm" будет переименован в "fldrnm-11042024-1530_name.ts". Формат даты должен быть в виде "ddmmyyyyyyyyyy".

Кроме того, этот .bat-файл не должен влиять на другие файлы, в начале которых уже есть этот тег.
{
"script": "@echo off\nsetlocal enabledelayedexpansion\nfor %%F in (*) do (\n set \"filename=%%~nxF\"\n set \"extension=%%~xF\"\n set \"foldername=%~dp0\"\n set \"foldername=!foldername:~0,-1!\"\n set \"tag=!foldername:~3!\"\n if not \"!filename:~0,12!\"==\"!tag!-\" (\n set \"datestamp=!date:~0,2!!date:~3,2!!date:~6,4!!time:~0,2!\"\n ren \"%%F\" \"!tag!-!datestamp!-%%F\"\n )\n)\nendlocal",
"description": "This .bat file script renames files in the folder where it is located. It adds a tag containing the folder name and the current date in the format ddmmyyyyyhh. It will not affect files that already have this tag at the beginning."
}
 
Please write a .bat file for windows 10 that renames files in the folder where the batch file is running. I need to add a tag containing the name of the folder where the file is located and the current date in the format. For example: a file like "1530_name.ts" lying in the folder "fldrnm" will be renamed to "fldrnm-11042024-1530_name.ts". The date format should be in the form "ddmmyyyy".

Also, this .bat file should not affect other files that already have this tag at the beginning.
 
Please write a .bat file for windows 10 that renames files in the folder where the batch file is running. I need to add a tag containing the name of the folder where the file is located and the current date in the format. For example: a file like "1530_name.ts" lying in the folder "fldrnm" will be renamed to "fldrnm-11042024-1530_name.ts". The date format should be in the form "ddmmyyyy".

Also, this .bat file should not affect other files that already have this tag at the beginning.
{
"script": "@echo off\nsetlocal enabledelayedexpansion\nfor %%F in (*) do (\n set \"filename=%%~nxF\"\n set \"extension=%%~xF\"\n set \"foldername=%~dp0\"\n set \"foldername=!foldername:~0,-1!\"\n set \"tag=!foldername:~3!\"\n if not \"!filename:~0,12!\"==\"!tag!-\" (\n set \"datestamp=!date:~0,2!!date:~3,2!!date:~6,4!\"\n ren \"%%F\" \"!tag!-!datestamp!-%%F\"\n )\n)\nendlocal",
"description": "This .bat file script renames files in the folder where it is located. It adds a tag containing the folder name and the current date in the format ddmmyyyy. It will not affect files that already have this tag at the beginning."
}
 
Назад
Сверху Снизу