Hi everyone,

I'm trying to create a script that gives the user the option to select a
source folder and a destination folder. What I want to do is:

- delete all files in destination folder
- randomly, copy files from the source folder to the destination folder,
until destination folder is full

But I'm having trouble with the second part, since I don't know how to use
the Rnd function to randomly select files in the source folder.

Any ideas?

Thanks, from Spain

RE: Copy random files from one folder to another by KevinC

KevinC
Thu Jan 25 14:41:00 CST 2007

If you could create and array of the names of all files in the folder then
knowing the size of the array could randomize numbers in that set and then
use the name to copy the file ... if you follow me ... i'm going to start
coding this out but if someone else already has some of the snips needed its
a start.
--
Kevin Callanan
MSCA 2003, A+, Network+
www.weblabtechs.com

Please let us know if this response was helpful...


"Juan in msnews" wrote:

> Hi everyone,
>
> I'm trying to create a script that gives the user the option to select a
> source folder and a destination folder. What I want to do is:
>
> - delete all files in destination folder
> - randomly, copy files from the source folder to the destination folder,
> until destination folder is full
>
> But I'm having trouble with the second part, since I don't know how to use
> the Rnd function to randomly select files in the source folder.
>
> Any ideas?
>
> Thanks, from Spain
>
>
>
>

Re: Copy random files from one folder to another by Gino

Gino
Thu Jan 25 20:10:14 CST 2007

Please write a clear and detailed objective.

What is ? (- randomly, copy files ) randomly copy some file, randomly copy
all files
randomly choose files based on what.
And what is ? (until destination folder is full) does that mean 100 files or
1000 files, or
until the hard drive explodes.

"Juan in msnews" <juan_magana@hotmail.com> wrote in message
news:elA5f4JQHHA.992@TK2MSFTNGP06.phx.gbl...
> Hi everyone,
>
> I'm trying to create a script that gives the user the option to select a
> source folder and a destination folder. What I want to do is:
>
> - delete all files in destination folder
> - randomly, copy files from the source folder to the destination folder,
> until destination folder is full
>
> But I'm having trouble with the second part, since I don't know how to use
> the Rnd function to randomly select files in the source folder.
>
> Any ideas?
>
> Thanks, from Spain
>
>
>



Re: Copy random files from one folder to another by KevinC

KevinC
Fri Jan 26 00:05:00 CST 2007

when i first looked at this post i looked at it with the idea of having 1000
songs on a server and writing a script to randomly select as may songs as it
could to fit on a remote location then maybe run a media player file ....
maybe this is something that is to be done daily ... maybe to change it up a
bit ...
--
Kevin Callanan
MSCA 2003, A+, Network+
www.weblabtechs.com

Please let us know if this response was helpful...


"Gino" wrote:

> Please write a clear and detailed objective.
>
> What is ? (- randomly, copy files ) randomly copy some file, randomly copy
> all files
> randomly choose files based on what.
> And what is ? (until destination folder is full) does that mean 100 files or
> 1000 files, or
> until the hard drive explodes.
>
> "Juan in msnews" <juan_magana@hotmail.com> wrote in message
> news:elA5f4JQHHA.992@TK2MSFTNGP06.phx.gbl...
> > Hi everyone,
> >
> > I'm trying to create a script that gives the user the option to select a
> > source folder and a destination folder. What I want to do is:
> >
> > - delete all files in destination folder
> > - randomly, copy files from the source folder to the destination folder,
> > until destination folder is full
> >
> > But I'm having trouble with the second part, since I don't know how to use
> > the Rnd function to randomly select files in the source folder.
> >
> > Any ideas?
> >
> > Thanks, from Spain
> >
> >
> >
>
>
>

Re: Copy random files from one folder to another by Juan

Juan
Fri Jan 26 03:25:25 CST 2007

That's exactly the idea... sorry I wasn't more clear before.

I'll try to "build" the array you suggest so I can randomly select elements
of that array...

Thanks, from Spain


"Kevin C" <KevinC@discussions.microsoft.com> escribió en el mensaje
news:D45EDEEF-1EEF-4F6B-B9BC-702935F7A01F@microsoft.com...
> when i first looked at this post i looked at it with the idea of having
1000
> songs on a server and writing a script to randomly select as may songs as
it
> could to fit on a remote location then maybe run a media player file ....
> maybe this is something that is to be done daily ... maybe to change it up
a
> bit ...
> --
> Kevin Callanan
> MSCA 2003, A+, Network+
> www.weblabtechs.com
>
> Please let us know if this response was helpful...
>
>
> "Gino" wrote:
>
> > Please write a clear and detailed objective.
> >
> > What is ? (- randomly, copy files ) randomly copy some file, randomly
copy
> > all files
> > randomly choose files based on what.
> > And what is ? (until destination folder is full) does that mean 100
files or
> > 1000 files, or
> > until the hard drive explodes.
> >
> > "Juan in msnews" <juan_magana@hotmail.com> wrote in message
> > news:elA5f4JQHHA.992@TK2MSFTNGP06.phx.gbl...
> > > Hi everyone,
> > >
> > > I'm trying to create a script that gives the user the option to select
a
> > > source folder and a destination folder. What I want to do is:
> > >
> > > - delete all files in destination folder
> > > - randomly, copy files from the source folder to the destination
folder,
> > > until destination folder is full
> > >
> > > But I'm having trouble with the second part, since I don't know how to
use
> > > the Rnd function to randomly select files in the source folder.
> > >
> > > Any ideas?
> > >
> > > Thanks, from Spain
> > >
> > >
> > >
> >
> >
> >
>




Re: Copy random files from one folder to another by Michael

Michael
Fri Jan 26 06:51:58 CST 2007

On Fri, 26 Jan 2007 10:25:25 +0100, Juan in msnews wrote in
microsoft.public.scripting.vbscript:

>That's exactly the idea... sorry I wasn't more clear before.
>
>I'll try to "build" the array you suggest so I can randomly select elements
>of that array...

Then you need to revise the concept of randomness - which normally will
not exclude that a number is drawn more than once. The following
untested pseudocode will draw a filename only once:

Do Forever
lngRandom = RndBetween(1, nFiles)
If FileSize(theFiles[lngRandom]) .GT. FreeSpace(theTarget) Exit Loop
CopyFile(theFiles[lngRandom], strTargetDir)
theFiles[lngRandom] = theFiles[nFiles]
--nFiles
Loop

where theFiles[] is an array of the source filenames, and nFiles is
their initial number (how many). Array subscripts are noted "[]",
function arguments "()".

>"Kevin C" <KevinC@...> escribió en el mensaje
>news:D45EDEEF-1EEF-4F6B-B9BC-702935F7A01F@microsoft.com...
>> when i first looked at this post i looked at it with the idea of having 1000
>> songs on a server and writing a script to randomly select as may songs as it
>> could to fit on a remote location then maybe run a media player file ....
>> maybe this is something that is to be done daily ... maybe to change it up a
>> bit ...
>>
>> "Gino" wrote:
>> > Please write a clear and detailed objective.
>> >
>> > What is ? (- randomly, copy files ) randomly copy some file, randomly copy
>> > all files
>> > randomly choose files based on what.
>> > And what is ? (until destination folder is full) does that mean 100 files or
>> > 1000 files, or
>> > until the hard drive explodes.
>> >
>> > "Juan in msnews" <juan_magana@...> wrote in message
>> > news:elA5f4JQHHA.992@TK2MSFTNGP06.phx.gbl...
>> > > I'm trying to create a script that gives the user the option to select a
>> > > source folder and a destination folder. What I want to do is:
>> > >
>> > > - delete all files in destination folder
>> > > - randomly, copy files from the source folder to the destination folder,
>> > > until destination folder is full
>> > >
>> > > But I'm having trouble with the second part, since I don't know how to use
>> > > the Rnd function to randomly select files in the source folder.

--
Michael Bednarek http://mbednarek.com/ "POST NO BILLS"

Re: Copy random files from one folder to another by E

E
Fri Jan 26 18:45:46 CST 2007

I was waiting to see where this lead, even if used as stated, put the wrong target and you could
have some issues. I also wonder what heuristics would think of this

Gino wrote:
> Please write a clear and detailed objective.
>
> What is ? (- randomly, copy files ) randomly copy some file, randomly copy
> all files
> randomly choose files based on what.
> And what is ? (until destination folder is full) does that mean 100 files or
> 1000 files, or
> until the hard drive explodes.
>
<SNIP>

Re: Copy random files from one folder to another by Gino

Gino
Sat Jan 27 20:32:59 CST 2007

'Hope this helps the rain in spain.
'Watch for line wrap.

Dim objFso
Dim objDictionary
Dim fileCount
Dim numberArray(100)
Dim indexNum
indexNum = 0

Set objFso = CreateObject("scripting.filesystemobject")
Set objFolder = objFso.GetFolder("C:\Data")
Set objFiles = objFolder.Files
fileCount = objFiles.Count
Set objDictionary = CreateObject("scripting.dictionary")

For Each fileName In objFiles
objDictionary.Add indexNum, fileName
indexNum = indexNum + 1
Next
'WScript.Echo objDictionary.Item(10)
For i = 0 To 99
Randomize
RandomNumber = Int((fileCount * Rnd) + 1)
numberArray(i) = RandomNumber
Next

For j = 0 To 99
For k = 0 To 99
If numberArray(k) = numberArray(k + 1) Then
numberArray(k) = numberArray(k) + 1
End If
If numberArray(k) > numberArray(k + 1) Then
temp = numberArray(k + 1)
numberArray(k + 1) = numberArray(k)
numberArray(k) = temp
End If
Next
Next

For L = 1 To 99
objFso.CopyFile objDictionary.item(numberArray(L)), "C:\Destination\"
Next

Set objFso = Nothing
Set objDictionary = Nothing

"Juan in msnews" <juan_magana@hotmail.com> wrote in message
news:elA5f4JQHHA.992@TK2MSFTNGP06.phx.gbl...
> Hi everyone,
>
> I'm trying to create a script that gives the user the option to select a
> source folder and a destination folder. What I want to do is:
>
> - delete all files in destination folder
> - randomly, copy files from the source folder to the destination folder,
> until destination folder is full
>
> But I'm having trouble with the second part, since I don't know how to use
> the Rnd function to randomly select files in the source folder.
>
> Any ideas?
>
> Thanks, from Spain
>
>
>



Re: Copy random files from one folder to another by Richard

Richard
Wed Jan 31 15:48:32 CST 2007

The Randomize function should be used once at the beginning of the script,
to seed the random number generator with a value based on the system time.
If you call Randomize before each call to Rnd, the resulting sequence will
no longer be random, since you are continually re-seeding the generator.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab web site - http://www.rlmueller.net
--

"Gino" <someone@microsoft.com> wrote in message
news:%23xAglSoQHHA.4632@TK2MSFTNGP04.phx.gbl...
> 'Hope this helps the rain in spain.
> 'Watch for line wrap.
>
> Dim objFso
> Dim objDictionary
> Dim fileCount
> Dim numberArray(100)
> Dim indexNum
> indexNum = 0
>
> Set objFso = CreateObject("scripting.filesystemobject")
> Set objFolder = objFso.GetFolder("C:\Data")
> Set objFiles = objFolder.Files
> fileCount = objFiles.Count
> Set objDictionary = CreateObject("scripting.dictionary")
>
> For Each fileName In objFiles
> objDictionary.Add indexNum, fileName
> indexNum = indexNum + 1
> Next
> 'WScript.Echo objDictionary.Item(10)
> For i = 0 To 99
> Randomize
> RandomNumber = Int((fileCount * Rnd) + 1)
> numberArray(i) = RandomNumber
> Next
>
> For j = 0 To 99
> For k = 0 To 99
> If numberArray(k) = numberArray(k + 1) Then
> numberArray(k) = numberArray(k) + 1
> End If
> If numberArray(k) > numberArray(k + 1) Then
> temp = numberArray(k + 1)
> numberArray(k + 1) = numberArray(k)
> numberArray(k) = temp
> End If
> Next
> Next
>
> For L = 1 To 99
> objFso.CopyFile objDictionary.item(numberArray(L)), "C:\Destination\"
> Next
>
> Set objFso = Nothing
> Set objDictionary = Nothing
>
> "Juan in msnews" <juan_magana@hotmail.com> wrote in message
> news:elA5f4JQHHA.992@TK2MSFTNGP06.phx.gbl...
> > Hi everyone,
> >
> > I'm trying to create a script that gives the user the option to select a
> > source folder and a destination folder. What I want to do is:
> >
> > - delete all files in destination folder
> > - randomly, copy files from the source folder to the destination folder,
> > until destination folder is full
> >
> > But I'm having trouble with the second part, since I don't know how to
use
> > the Rnd function to randomly select files in the source folder.
> >
> > Any ideas?
> >
> > Thanks, from Spain
> >
> >
> >
>
>



Re: Copy random files from one folder to another by Bob

Bob
Wed Jan 31 18:25:43 CST 2007

Richard Mueller [MVP] wrote:
> The Randomize function should be used once at the beginning of the script,
> to seed the random number generator with a value based on the system time.
> If you call Randomize before each call to Rnd, the resulting sequence will
> no longer be random, since you are continually re-seeding the generator.
>

I agree strongly with the recommendation, but not with your description of why.
The resulting sequence may be badly distributed, but will in fact still be _random_

For example, a bent coin which falls heads twice as often as tails is still *random*
it just doesn't have other generally expected characteristics such as what one might
call "fairness"


Bob
--

Re: Copy random files from one folder to another by Gino

Gino
Wed Jan 31 21:09:24 CST 2007

I agree. Looking at it I think what will happen is if the number of files
pool was around 1000 and I was selecting 100 the high end number would never
get above 300.
Thanks for pointing that out.

"Richard Mueller [MVP]" <rlmueller-NOSPAM@ameritech.NOSPAM.net> wrote in
message news:%23YoFLHYRHHA.412@TK2MSFTNGP02.phx.gbl...
> The Randomize function should be used once at the beginning of the script,
> to seed the random number generator with a value based on the system time.
> If you call Randomize before each call to Rnd, the resulting sequence will
> no longer be random, since you are continually re-seeding the generator.
>
> --
> Richard
> Microsoft MVP Scripting and ADSI
> Hilltop Lab web site - http://www.rlmueller.net
> --
>
> "Gino" <someone@microsoft.com> wrote in message
> news:%23xAglSoQHHA.4632@TK2MSFTNGP04.phx.gbl...
>> 'Hope this helps the rain in spain.
>> 'Watch for line wrap.
>>
>> Dim objFso
>> Dim objDictionary
>> Dim fileCount
>> Dim numberArray(100)
>> Dim indexNum
>> indexNum = 0
>>
>> Set objFso = CreateObject("scripting.filesystemobject")
>> Set objFolder = objFso.GetFolder("C:\Data")
>> Set objFiles = objFolder.Files
>> fileCount = objFiles.Count
>> Set objDictionary = CreateObject("scripting.dictionary")
>>
>> For Each fileName In objFiles
>> objDictionary.Add indexNum, fileName
>> indexNum = indexNum + 1
>> Next
>> 'WScript.Echo objDictionary.Item(10)
>> For i = 0 To 99
>> Randomize
>> RandomNumber = Int((fileCount * Rnd) + 1)
>> numberArray(i) = RandomNumber
>> Next
>>
>> For j = 0 To 99
>> For k = 0 To 99
>> If numberArray(k) = numberArray(k + 1) Then
>> numberArray(k) = numberArray(k) + 1
>> End If
>> If numberArray(k) > numberArray(k + 1) Then
>> temp = numberArray(k + 1)
>> numberArray(k + 1) = numberArray(k)
>> numberArray(k) = temp
>> End If
>> Next
>> Next
>>
>> For L = 1 To 99
>> objFso.CopyFile objDictionary.item(numberArray(L)), "C:\Destination\"
>> Next
>>
>> Set objFso = Nothing
>> Set objDictionary = Nothing
>>
>> "Juan in msnews" <juan_magana@hotmail.com> wrote in message
>> news:elA5f4JQHHA.992@TK2MSFTNGP06.phx.gbl...
>> > Hi everyone,
>> >
>> > I'm trying to create a script that gives the user the option to select
>> > a
>> > source folder and a destination folder. What I want to do is:
>> >
>> > - delete all files in destination folder
>> > - randomly, copy files from the source folder to the destination
>> > folder,
>> > until destination folder is full
>> >
>> > But I'm having trouble with the second part, since I don't know how to
> use
>> > the Rnd function to randomly select files in the source folder.
>> >
>> > Any ideas?
>> >
>> > Thanks, from Spain
>> >
>> >
>> >
>>
>>
>
>