Best way to rename files in a directory?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SIMMS7400
Posts: 539
Joined: 07 Jan 2016 07:47

Best way to rename files in a directory?

#1 Post by SIMMS7400 » 24 Jul 2017 12:40

HI Folks -

I have a process at work where 'Workday' (an HR tool) drops off a set of files on a share. Then, my process picks them up and processes them.

However, the files they drop off have weird naming conventions, so I rename them to a format more easily digestible for my automation.

My script right now is, somewhat, but sometimes no matter what's in %%H, it gets over written with the last rename line:

Code: Select all

PUSHD "%HC_PROCPATH%"

SETLOCAL ENABLEDELAYEDEXPANSION

SET "A=0"
SET "NF1="
FOR %%H IN (

   Zurich_Finance
   Deerfield_-_Finance_CW_Headcount
   Deerfield_-_Finance_Employee_Headcount_IA
   Deerfield_-_Finance_Employee_Headcount ) DO (

   IF EXIST %%H* (
   
      ECHO Headcount File Detected ^: %%H*.%EXT% >>"%LOGFILE%"
      ECHO %%H* | FINDSTR "CW">nul && REN "%%H*" "Contractors_%HC_STRING%_CW.%EXT%"
      ECHO %%H* | FINDSTR "IA">nul && REN "%%H*" "Secondees_%HC_STRING%_IA.%EXT%"
      ECHO %%H* | FINDSTR "Zurich">nul && REN "%%H*" "%HC_ZUR%.%EXT%"
      REN "%%H*" "Employees_%HC_STRING%.%EXT%"
   ) ELSE (
      SET /A A+=1
   )
IF !A!==4 SET "NF1=T"& GOTO AbnormalExit
CLS
)
POPD


I'm using a wildcard because the strings dates and other characters on the end. Is there a better way to do this?

Thanks!

pieh-ejdsch
Posts: 239
Joined: 04 Mar 2014 11:14
Location: germany

Re: Best way to rename files in a directory?

#2 Post by pieh-ejdsch » 26 Jul 2017 14:31

In HC_procpath there are how man files?
A Set oft Files has everytimes four Names?
the second Part oft these names have everyone the same?

Post Reply