Login | |
|
 |
RE: need help moving set of files randomly - 7/14/2006 1:46:12 AM
|
|
 |
|
| |
ebgreen
Posts: 4970
Score: 31
Joined: 7/12/2005
Status: offline
|
That would move all the files listed. To move a subset of the files you would need to: Create an array of the file names get a random number between 0 and the UBound of the array Move that file Swap that item of the array with the last item in the array Redim preserve the array to one less than it currently is repeat for a many files as you want to move
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: need help moving set of files randomly - 7/15/2006 1:44:11 PM
|
|
 |
|
| |
DiGiTAL.SkReAM
Posts: 1183
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
|
I'll excercise my Dictionary fetish, and even though ebgreen has already answered, I'll post this. At least it's a different angle. [code] Set oDic = CreateObject("Scripting.Dictionary") For Each file In CreateObject("Scripting.FileSystemObject").GetFolder("c:\working").Files oDic.Add oDic.Count,file Next Randomize For i = 1 To 6 x = Int(((oDic.Count - 1) - 0 + 1) * Rnd + 0) CreateObject("Scripting.FileSystemObject").GetFile(oDic.Item(x)).Move "c:\temporary1\" oDic.Remove(x) Next [/code I know that I should have been able to do this same function in 3 or fewer lines, but I guess I'm just wordy. And frankly, I really like the functionality of the dictionary - being able to remove a key/item pair and have all the counts auto-adjust makes it very handy for situations like this.
_____________________________
"Would you like to touch my monkey?" - Dieter (Mike Meyers) "It is better to die like a tiger, than to live like a pussy." -Master Wong, from Balls of Fury
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|