Thank you.
Thanks to all especially Scott and Michael for their help. I saw the dir$ close and read the warning. I remember working on AS400 and doing something that affected filenames (i think delete) and the program ran wild for hours continuing to re-read through a specific library. Maybe similar to rename/delete under DIR$.
Announcement
Collapse
No announcement yet.
rename files in folder using pbcc
Collapse
X
-
Actually, anything which affects the directory - rename a file, add a file - can mess up a DIR$ or FindFirstFile/FindNextFile loop. I can't remember if deleting a file will as well, but after getting burned by rename and add, I don't even bother to play with that fire anymore.
You can also do something like this...
Code:SPEC$ = "*.ext" DO S = DIR$(spec$) IF LEN (S) THEN DIR$ CLOSE NAME S AS NewName ELSE EXIT DO END IF LOOP
Leave a comment:
-
Also, be aware that the NAME statement does NOT support wild cards. You have to (re)name a specific file name to another specific file name.
Leave a comment:
-
Originally posted by Michael Mattias View PostDon't rename WITHIN a DO..LOOP! It screws up the DIR$ NEXT.
Make a list (array) of files in the folder, then NAME them one at a time after DIR$ CLOSE.
Code:Sub RenameAll(ByVal sFolder As String) Local dCount As Dword Local idx As Dword Local sFile As String Dim sFileList() As String Do If dCount = 0 Then ' Initialize Dir$ sFile = Dir$(sFolder & "*.EXT") ' use whatever extension here or use * with caution Else sFile = Dir$ End If If Len(sFile) = 0 Then Exit Loop Incr dCount ReDim Preserve sFileList(1 To dCount) As String sFileList(dCount) = sFolder & sFile Loop For idx = 1 To dCount Name sFileList(idx) As sFolder & "topic" & Format$(idx, "0000") & ".EXT" If Err Then Exit For Next idx End Sub
Last edited by Scott Slater; 18 Mar 2009, 09:26 AM.
Leave a comment:
-
Here's a crude example of what I am referring to. This has not been tested, as I am just writing it now.
Code:' This does not check sFolder, but it should be done. ' This routine was written for demo purposes only. ' sFolder needs to end with a trailing \ backslash Sub RenameAll(ByVal sFolder As String) Local dCount As Dword Local sFile As String Do If dCount = 0 Then ' Initialize Dir$ sFile = Dir$(sFolder & "*.EXT") ' use whatever extension here or use * with caution Else sFile = Dir$ End If If Len(sFile) = 0 Then Exit Loop Incr dCount Name sFolder & sFile As sFolder & "topic" & Format$(dCount, "0000") & ".EXT" If Err Then Exit Loop Loop End Sub
Leave a comment:
-
Don't rename WITHIN a DO..LOOP! It screws up the DIR$ NEXT.
Make a list (array) of files in the folder, then NAME them one at a time after DIR$ CLOSE.
Leave a comment:
-
See the NAME keyword for renaming. If you want to do a certain group of files then also see DIR$ since you could use a loop and DIR$ to rename multiple files that match a certain filespec.
Leave a comment:
-
rename files in folder using pbcc
I want to flip through a specific folder and generically rename all files within this folder (topic0001, topic0002, etc). Currently the files in folder have names that are hard to follow and control.
What do I need? sample program???
(no. not dialog box but direct change)
Thank you.Tags: None
Leave a comment: