1

My goal is to create something in my Windows Server 2016 that renames all files in a folder continuously. But, I do not know a way of doing so. I have done some research about this but I only have found tools that rename files when you click it. What I want to do is create a continuous schedule that everytime that it's created a file in an folder it renames it with a prefix, with the date and hour etc.

Does any of you know any way of doing so ?

Thank you.

Edit: What I want to do specifically is to create a continuous loop that renames All files in a folder, with any name, where it adds an prefix with date and hour

2 Answers2

0

A very simple .bat file can do the job:

@ECHO OFF
:loop
  ren old*.oldname new*.newname
  timeout /t 5 > NUL
goto loop

For more complicated renames see the article
How does the Windows RENAME command interpret wildcards?

harrymc
  • 498,455
0

My suggest for do this job, add some character in name, like code (for sample) using "#", filter files by list and if not match, rename it...

Sorry my limited English...

@echo off & setlocal enabledelayedexpansion

mode 50,4 & color 9F & title <nul & cls

rem :: go to the target folder, by edit 'set command in [set "_path_to_ren=."]' and repace to:
rem :: 'set "_path_to_ren=."' by set/add your full target path: "d:\folder\where\are\this\files"

set "_path_to_ren=." & cd /d "!_path_to_ren!"

:^| 
title <nul & echo/ & echo/ Working in looping... & echo ========================== 

for /f %%i in ('%__APPDIR__%wbem\wmic.exe OS Get localdatetime^|find "."')do set "_dt=%%~i"
title Renaming in Looping: !_dt:~0,4!/!_dt:~4,2!/!_dt:~6,2! !_dt:~8,2!:!_dt:~10,2!:!_dt:~15,2! 

for /f "tokens=*delims= " %%i in ('%__APPDIR__%where.exe .:"*"^|%__APPDIR__%findstr.exe /v \\#[0-9]^|find/v "%~0"
')do 2>nul ren "%%~i" "#!_dt:~0,4!-!_dt:~4,2!-!_dt:~6,2!-!_dt:~8,2!-!_dt:~10,2!-!_dt:~12,2!_%%~nxi" >nul

%__APPDIR__%timeout.exe /t 1 >nul & goto :^|

| LoopRen.cmd | : FileName.Ext

| Get Results | : #2020-06-28-13-00-57_FileName.Ext


enter image description here


Obs.: Get date by wmic following this:


Safe way to get current day month and year in batch

Parsing Dates in Batch Files & Regional Settings / Locale

Io-oI
  • 9,237