Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: File Rename FileRename StrFixLeft Pad
; Code posted to WinBatch Forum 2013.06.26 by kennytmcp DirChange("C:\Users\kenny\Desktop\SILH") ;set working dir. List1 = FileItemize("C:\Users\kenny\Desktop\SILH\*.PTN") ;list files in the dir I want to manupilate ptncount=ItemCount(List1,@TAB) ;File Count For xx=1 TO ptncount ;Loop = to the file count ptn=ItemExtract(xx,List1,@TAB) ; get one file name at ta time ptn1 = StrFixLeft(ptn, " ",8) ;fix string left to trim off all the way to the pattern number leaving the file name as 1234.PTN 8 characters ::) ptn2 = StrFixLeft(ptn1, "SILH-0000000",20) ; fix string left again, making the lenth 20 characaters using the desired padding string leaving new string ptn2 FileCopy(ptn, "C:\Users\kenny\Desktop\SILH\NEW\temp.ptn", @FALSE) ;copy files to a new folder and NEW name to save confusion. dirchange("C:\Users\kenny\Desktop\SILH\NEW\") ; change to the new directory filerename("temp.ptn",ptn2) ; rename temporary file name to the variable ptn2 the correct name dirchange("C:\Users\kenny\Desktop\SILH\") FileDelete( ptn ) ; Deletes original files Next ;finished loop so continue down. Message("Thats It", "all files were copied and renamed") ;end
Article ID: W17877
Filename: Tricky Bulk FileRename .txt
File Created: 2013:06:27:08:31:02
Last Updated: 2013:06:27:08:31:02