Rename Highest File Versions

Javascript renaming examples. Javascript renaming is supported in version 3 or newer.

Rename Highest File Versions

Postby SnickleFritz285 » Wed Jan 03, 2018 3:54 pm

I know nothing about java script but I need help deleting all previous file versions.
The Files are named as follows:
544401_A_01.prt
544401_A_02.prt
544401_B_01.prt
544401_C_01.prt
544401_C_02.prt

The string in red is always variable and never a constant string length
The string in blue has been normalized to always be 2 characters-This is the file version number
The String in green is always 1 character A-Z-This is the file revision
The underscores are always there and in the same place

I need to keep the highest Revision and the highest Version and have it renamed without the "_C_02".

is it also possible to delete/move the rest of the files so that i only have the most current files under one folder?

i know it probably makes more sense to do this by date created but since these were copied from the old database the time stamps were re-written and i don't know if they follow the correct chronological order.
SnickleFritz285
 
Posts: 3
Joined: Tue Jan 02, 2018 9:07 pm

Re: Rename Highest File Versions

Postby dude » Tue Sep 25, 2018 7:32 pm

Do you still need this?
dude
 

Re: Rename Highest File Versions

Postby dude » Wed Oct 31, 2018 9:14 am

Code: Select all
@echo off
setlocal
pushd "%~dp0"


rem if not EXIST OLDVERSIONS md OLDVERSIONS
set PREVIOUS=
setlocal enabledelayedexpansion
for /f "usebackq tokens=1-3 delims=_" %%a in (`dir /b /o:-n *.prt`) do call :sift "%%a" "%%b" "%%c"
endlocal
pause
goto :eof


::=============================================
:SIFT
::=============================================

   if "%~1" == "!PREVIOUS!" (
      echo FILE "%~1_%~2_%~3" : MOVE   to OLDVERIONS
   ) else (
      echo.
      echo FILE "%~1_%~2_%~3" : RENAME to "%~1.prt"
      set PREVIOUS=%~1
   )
goto :EOF
dude
 


Return to Javascript Renaming