troubleshooting Question

Rename Files  With Random Number/Number of Files

Avatar of G Scott
G ScottFlag for United States of America asked on
Microsoft Access
8 Comments1 Solution593 ViewsLast Modified:
Ok, so here is what I need to do. I have a folder with 8 avi files in it. Files are named 1.avi, 2.avi...etc. I want to rename those files so that file 1.avi will be a random file in the folder. I also want to be able to add files with the same naming convention and have it rename as many files as I put in there. So basically I just want to scramble the files in the folder.

I thought maybe having a table with the filenames in a column and then a random number column. It would just rename the filename to the random number. But I can't figure it out.
This is the code I found that I have been messing with:

Private Sub Command0_Click()

Const FILEPATH As String = _

Dim strfile As String
Dim filenum As String

strfile = Dir(FILEPATH)

Do While strfile <> ""
  Debug.Print strfile
  If Right$(strfile, 3) = "avi" Then
    filenum = Mid$(strfile, Len(strfile) - 6, 3)
    Name FILEPATH & strfile As FILEPATH & filenum & ".avi"
  End If

  strfile = Dir


End Sub

But it gives me the old 'Filename already exists." error. Which makes sense. I just can't figure out how to do this. Thanks for any help you can give me on this. It is very puzzling.
[ fanpages ]
Consultant (Development Team Lead, Senior Support Engineer, and Technical Test Leader)

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros