|
Post by Roger Cabo on Aug 21, 2022 20:23:54 GMT 1
Hi, during an accident a lot of files was renamed on my second win system. Files was renamed, so that spaces between char and and a literal are deleted. For example "file 001" was renamed to "file001.dat" , or "file 01.dat" to "file01.dat". Now I would love to rename these by regular expressions. So all files having no space between a char and a literal... should get a space between again. "abc001cde06x0.dat" to "abc 001 cde 06 x 0.dat"
Thank you.
|
|
|
Post by dragonjim on Aug 22, 2022 21:04:34 GMT 1
Hi,
There is a small code example on the Dir help page which you can alter to do what you wish to do:
OpenW 1 Local contents$, a% PrintScroll = True contents$ = Dir("c:\windows\*", $16) While Len(contents$) Print contents$ contents$ = Dir$ Wend
Currently, this just prints the contents of the chosen directory; however, by editing the contents of content$ and then using CopyFile ... OverTo ... you should be able to update your filenames.
|
|
|
Post by scalion on Sept 1, 2022 7:58:41 GMT 1
$Library "gfawinx" $Library "UpdateRT" UpdateRuntime ' Patches GfaWin23.Ocx OpenW 1 FontName = "System" FontSize = 12 Local contents$, renamed$, a% PrintScroll = True contents$ = Dir("c:\windows\*", $16) While Len(contents$) If And(GetAttr(), 16) = 0 // no directory, only files Print contents$ renamed = InsertSpaceInFilename(contents$) If renamed <> contents$ Print "->"; renamed; " (len=" & Len(renamed$) & ")" If Message("Rename "#34 & contents$ & #34" in "#34 & renamed & #34" ?", "Change found", MB_YESNO) = IDYES 'Rename contents$ As renamed EndIf EndIf EndIf contents$ = Dir$ Wend Do Sleep Loop Until Me Is Nothing Function InsertSpaceInFilename(Filename As String) As String Local Long V, i, Asc1, Asc2 Local String Result, Path, Extension, NewName Local Boolean isNum1, isNum2 V = RInStr(Filename & " " , ".") If V > 0 Extension = Mid(Filename, V) Filename = Mid(Filename, 1, V - 1) Else Extension = "" Filename = Filename EndIf V = RInStr(Filename & " ", "\") If V > 0 Path = Mid(Filename, 1, V) Filename = Mid(Filename, V + 1) Else Path = "" EndIf If Len(Filename) > 1 NewName = "" For i = 1 To Len(Filename) - 1 Asc1 = Asc(Filename, i) Asc2 = Asc(Filename, i + 1) isNum1 = (Asc1 >= 48 And Asc1 <= 57) isNum2 = (Asc2 >= 48 And Asc2 <= 57) NewName = NewName & Chr(Asc1) If (isNum1 Xor isNum2) And Asc1 <> 32 And Asc2 <> 32 NewName = NewName & " " EndIf Next i Add NewName , Chr(Asc2) Filename = NewName EndIf Return Path & Filename & Extension EndFunc
|
|