|
-
Jul 28th, 2000, 03:33 AM
#1
Thread Starter
Hyperactive Member
What is the best method of renaming a text file
code would be great, I am looking for the quickest way possible.
Many thanks
Locutus
-
Jul 28th, 2000, 03:56 AM
#2
The easiest way I know of is:
Name "c:\test.txt" As "c:\changed.txt"
-
Jul 28th, 2000, 03:59 AM
#3
Addicted Member
More control using this?
Code:
Private Sub RenameFile(strDest As String, strOld As String)
Dim fs, f
'Example files:
'
'strOld = "C:\WINDOWS\Desktop\TestFiles\OldFile.txt"
'strDest = "C:\WINDOWS\Desktop\TestFiles\NewFile.txt"
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(strOld)
f.Move strDest
Set f = Nothing
Set fs = Nothing
End Sub
-
Jul 28th, 2000, 04:31 AM
#4
I ran a test of Steves code and found that the "name f1 as f2" method was faster if your dealing with many files.
I renamed 150 files.
Name As : 1332 ticks
RenameFile : 1552 ticks
-
Jul 28th, 2000, 04:35 AM
#5
Addicted Member
ah...... but did you close/open the filesystem object each time?
Keep this bit running:
Set fs = CreateObject("Scripting.FileSystemObject")
Only reset this bit.
Set f = fs.GetFile(strOld)
No need to set x = nothing each time, just re-allocate the
variable, clean up at the end.
-
Jul 28th, 2000, 04:48 AM
#6
No I did not. I just used your function as you wrote it. Do you suggest that I test it with passing a filesystem object to your function so the overhead of creating a new object each time is remved. I dont think that is good programming, but it sertanly will speed up the process...
This was my test code:
c = GetTickCount
For i = 1 To 150
oldf = "c:\test\Kopia (" & i & ") av test.txt"
newf = "c:\test\Changed (" & i & "} av test.txt"
Name oldf As newf
Next i
d = GetTickCount
nt = d - c
c = GetTickCount
For i = 1 To 150
newf = "c:\test\Kopia (" & i & ") av test.txt"
oldf = "c:\test\Changed (" & i & "} av test.txt"
RenameFile newf, oldf
Next i
d = GetTickCount
rt = d - c
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|