;========================================================================================================================================== ; ; How to rename the file extension? ; ; Detlev Dalitz.20110124. ;========================================================================================================================================== ; The base filename includes both the file root and the file extension. ; The file extension is the righmost part of the base filename, delimited by a dot character. ; ; See functions: FileBaseName, FileRoot, FileExtension. ; If the file extension is empty, then the dot delimiter may disappear, so that "abc." is the same as "abc". strFN1 = "abc.def.txt" ; ==> extension = "txt" strFN2 = "abc.txt" ; ==> extension = "txt" strFN3 = "abc." ; ==> extension = "" strFN4 = "abc" ; ==> extension = "" ; Example 1. ; Set File Extension to "log". strExt = "log" ; Use WinBatch item related functions and in-line-logic. strFN1_New1 = ItemReplace (strExt, -1, strFN1 : StrSub (".", ItemCount (strFN1, ".") == 1, 1), ".") ; "abc.def.log" strFN2_New1 = ItemReplace (strExt, -1, strFN2 : StrSub (".", ItemCount (strFN2, ".") == 1, 1), ".") ; "abc.log" strFN3_New1 = ItemReplace (strExt, -1, strFN3 : StrSub (".", ItemCount (strFN3, ".") == 1, 1), ".") ; "abc.log" strFN4_New1 = ItemReplace (strExt, -1, strFN4 : StrSub (".", ItemCount (strFN4, ".") == 1, 1), ".") ; "abc.log" ; Example 2. ; Set File Extension to "log". strDotExt = ".log" ; See what WinBatch filename functions can do. strFN1_R = FileRoot (strFN1) ; "abc.def" strFN1_E = FileExtension (strFN1) ; "txt" strFN2_R = FileRoot (strFN2) ; "abc" strFN2_E = FileExtension (strFN2) ; "txt" strFN3_R = FileRoot (strFN3) ; "abc" strFN3_E = FileExtension (strFN3) ; "" strFN4_R = FileRoot (strFN4) ; "abc" strFN4_E = FileExtension (strFN4) ; "" ; Use WinBatch FileRoot function and string concatenation. strFN1_New2 = FileRoot (strFN1) : strDotExt ; "abc.def.log" strFN2_New2 = FileRoot (strFN2) : strDotExt ; "abc.log" strFN3_New2 = FileRoot (strFN3) : strDotExt ; "abc.log" strFN4_New2 = FileRoot (strFN4) : strDotExt ; "abc.log" Exit