How to create .BAT to rename multiple files in multiple folders by inserting creation date and time?

5

Does anyone know how to create .bat to rename multiple files in multiple folders by inserting creation date and time, not the current date?

Example:

Nome                        Data e hora de Criação

SCP Dados.mdb               03/06/2016 10:26

After renaming is to look like this:

Nome                        Data e hora de Criação

SCP Dados030616-1026.mdb    03/06/2016 10:26

Deleting any character before and after the created name leaving the extension .mdb " <-SCP Dados030616-1026->.mdb "

I've already done this:

@echo   Renomeando arquivo SCP Dados.mdb da BAHIA (BKP Manha)

dir \S1WKSPCRCI\B$\CIBackups\Backup_BA\"SCP Dados.mdb" [AQUI ME MOSTRA A DATA]

set /p dt_arq_ba= Digite a DATA de Criacao do Arquivo da BAHIA: [AQUI INSIRO A DATA]

ren \S1WKSPCRCI\B$\CIBackups\Backup_BA\SCP?Dados.mdb "SCP Dados%dt_arq_ba%.mdb" [AQUI ME DA O ARQUIVO RENOMEADO]

It is working, but only manually renames one by one, wanted to automate with the date the file was created.

    
asked by anonymous 09.08.2016 / 18:58

1 answer

0

:: 1) List the files and redirect the output to   "%temp%\_file_origem.txt"

:: 2) Use a for loop to get the paths and port to the WMIC "\"="\\"

:: 3) Use another for loop to get the creation date and save a variable to rename.

:: 4) Adjust the output date of the creation date to the desired format:

:: 5) Set the new file name and rename by removing unwanted characters:

cd /d %~dp0 & cls && @echo off & setlocal enableextensions enabledelayedexpansion

echo  Renomeando arquivo SCP Dados.mdb da BAHIA ^(BKP Manha^)

:: 1 ::

if exist "%temp%\_file_origem.txt" del /q /f "%temp%\_file_origem.txt"
if exist "%temp%\_file_target.txt" del /q /f "%temp%\_file_target.txt"

for %%i in (target origem) do type nul >"%temp%\_file_%%i.txt"

dir /a:-d /b /s "\S1WKSPCRCI\B$\CIBackups\Backup_BA\*.mdb" >>"%temp%\_file_origen.txt"

:: 2 ::

for /f "tokens=* delims=^ " %%i in ('type "%temp%\_file_origem.txt") do ( 

          set _file_=%%~i
     call set _file=!_file!

          set "_path_file=%%~dpi"
     call set "_path_file=!_path_file!"

          set "_file_to_wmic=!_file_:\=\!"
     call set "_file_to_wmic=!_file_to_wmic!"

:: 3 ::

     for /f "tokens=* delims=^ " %%I in "('wmic datafile where name='!_file_to_wmic!' get "creationdate" | findstr /v "CreationDate"') do ( 

         set _date_create=%%I
:: 4 ::

         call set _date_create=!_date_create:~7,2!!_date_create:~5,2!!_date_create:~3,3!-!_date_create:~9,4!
         call set _new_name="SCP Dados!_date_create!.mdb"
:: 5 ::  

         ren "!_file_!" "!_new_name!"

        )

    )
    
03.12.2018 / 03:23