Rename non-specific files???

NJudson

Who farted?
Local time
Today, 14:03
Joined
Feb 14, 2002
Messages
297
I have a set of files that (approx 500) .doc files that I want to convert to txt and rename. I know that there is someway to do it for specified filenames but I would like to just go down the list of files in the folder and rename them numerically. For example:

Existing file names
KPCR1344.DOC
KLFD1432.DOC
QRWCT13.DOC
STHB4451.DOC
SGUIW332.DOC

Rename these to
K1.TXT
K2.TXT
Q1.TXT
S1.TXT
S2.TXT

How can I go about doing this? I'm using Access 2k on Win98.

Thanks.
 
Try the code below and see how it works for you.

Private Function fGetFiles2()

Dim objFS As Object, objFolder As Object
Dim objFiles As Object, objF1 As Object
Dim strFolderPath As String, strDoc As String
Dim I As Integer, J As Integer

strFolderPath = "i:/test/"
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFS.GetFolder(strFolderPath)
Set objFiles = objFolder.files

For I = 65 To 122
J = 1
For Each objF1 In objFiles
strDoc = Left(objF1.Name, 1)
If strDoc = Chr(I) And Right(objF1.Name, 3) = "doc" Then
OpenDoc strFolderPath & objF1.Name, strFolderPath & strDoc & J
J = J + 1
End If
Next
Next I

Set objF1 = Nothing
Set objFiles = Nothing
Set objFolder = Nothing
Set objFS = Nothing

End Function

Function OpenDoc(strDocName As String, strTxtName As String)
Dim objWord As Object
Set objWord = CreateObject("Word.Application")
With objWord
.Visible = False
.Documents.Open FileName:=strDocName
.ActiveDocument.SaveAs FileName:=strTxtName, FileFormat:=2 'wdFormatText"
End With
objWord.Quit
Set objWord = Nothing
End Function


Change the strFolderPath to yours. I have tested with 4 files you said and it turned out OK. Let me how it goes with yours.
 

Users who are viewing this thread

Back
Top Bottom