You can read all of the files in a directory as:
Dim strFolder As String
Dim strFile As String
strFolder = "C:\Some Folder\"
strFile = Dir$(strFolder) & "*.*"
Do While Len(strFile) > 0
Debug.Print strFile
strFile = Dir$()
Loop
I think in this case, you might need to build an array of existing files,
though, as I'm not sure whether Dir is smart enough to ignore the renamed
files.
Dim intLoop
Dim strFolder As String
Dim strFile As String
Dim strNewName As String
Dim strExistingFiles() As String
intLoop = 0
ReDim strExistingFiles(0 to intLoop + 9)
strFolder = "C:\Some Folder\"
strFile = Dir$(strFolder) & "*.*"
Do While Len(strFile) > 0
If (intLoop Mod 10) = 0 Then
ReDim Preserve strExistingFiles(0 to intLoop + 9)
End If
strExistingFiles(intLoop) = strFile
intLoop = intLoop + 1
strFile = Dir$()
Loop
ReDim Preserve strExistingFiles(0 to (intLoop - 1))
For intLoop = LBound(strExistingFiles) To UBound(strExistingFiles)
' Figure out what strNewName should be
Name strFolder & strExistingFiles(intLoop) As strFolder & strNewName
Next intLoop
Note that this is untested "aircode".
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"Larry R Harrison Jr" <no***@noone.com> wrote in message
news:TtuPc.16546$Xn.13470@fed1read05...
I have Access XP. I know Visual Basic quite well. One thing I know Access
can do--and I can't quite figure out how--is to rename the files in a
directory.
If the file is named "aug01_003.jpg" I want to rename it 2004_08_003.jpg.
I can understand how to do it to this extent:
Ch Dir () ' whatever directory these files are located in
Dim stOldName as string, stNewName as string
stOldName = 'whatever syntax would go here to 'sense' the "next" file
stNewName = "2004_08_" & mid(stOldName,7,3) & ".JPG"
Name stOldName as stNewName
I could see everything after Ch Dir being contained in a loop which tells
it basically to do this to every file until the end of the directory is
reached. That's where I am stuck, as well as what I set stOldName equal
to.
Tips?
LRH