Extract file name with largest suffix
Posted: 14 Dec 2017 18:35
Hi Folks -
I have a text file I pull down from a cloud environment which I need to parse and then based off that file, download that file.
Here is a sample file:
The only content I care about is as follows : outbox/logs/Client_
My code to grab only that content and figure out the highest 4 digit suffix is as follows:
Is my method acceptable or is there a better way?
Thank you.
I have a text file I pull down from a cloud environment which I need to parse and then based off that file, download that file.
Here is a sample file:
Code: Select all
inbox/EBS/Client_GL_Detail_PBCS_121017_NOV2017.txt
inbox/EBS/Client_GL_Detail_PBCS_121017_OCT2017.txt
inbox/EBS/Client_GL_Detail_PBCS_121117_DEC2017.txt
inbox/EBS/Client_GL_Detail_PBCS_121117_NOV2017.txt
inbox/EBS/Client_GL_Detail_PBCS_121117_OCT2017.txt
inbox/Client/Client_GL_Detail_PBCS_111417_SEP2017.txt
inbox/Client/Client_GL_Detail_PBCS_111417_SEP2017.xls
outbox/Client_2678.dat
outbox/Client_2682.dat
outbox/logs/Client_2954.log
outbox/logs/Client_2955.log
outbox/logs/Client_2956.log
outbox/logs/Client_2957.log
outbox/logs/Client_2958.log
outbox/logs/Client_2959.log
outbox/logs/Client_2960.log
outbox/logs/Client_2961.log
outbox/logs/Client_2962.log
outbox/logs/Client_2963.log
outbox/logs/Client_2964.log
Total 489
My code to grab only that content and figure out the highest 4 digit suffix is as follows:
Code: Select all
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "MAXFILE="
FOR /F "tokens=*" %%A IN ('FINDSTR /c:"outbox/logs/Client_" file.txt') DO (
SET "NAME=%%~nA"
IF !NAME! GTR !MAXFILE! SET "MAXFILE=!NAME!"
)
ECHO file is : %MAXFILE%
pause
Thank you.