1st, my apologies if my English is not perfect
But i have troubles to create a working VBS script.
To be honest i'm a 99% noob concerning VBS, and i'd like to make a script that will do 2 things :
- in a folder C:\test\Default Pictures\ which contains many *.BMP files, i need to randomly select one of these.
- then, copy this file as USER.BMP, in the Parent folder : C:\test\
I googled many things & did some tests, but i'm not good enough to make it work.
my most recent script is:
Quote
Dim vProgData
Dim objFolder
Dim oFSO,oFl
Dim objFile
Dim objNbr
Set WshShell = WScript.CreateObject("Wscript.Shell")
vProgData = WshShell.ExpandEnvironmentStrings("%systemdrive%")
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(vProgData & "\test\Default Pictures\")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFl = oFSO.GetFolder(objFolder).Files
Randomize
For i=1 To oFl.Count
objNbr = Int(oFl.Count * Rnd + 1)
Next
MsgBox objNbr (line written to see if the Random Selection works : it's OK, it randomly gives me a number between 1 and the number of the files)
Set objFile = oFSO.Name(objNbr) (troubles start from here, as you can see i'm not familiar with VB and i don't see how to "convert" this random number above to the corresponding file in the folder)
''oFSO.CopyFile "objFolder\Default Pictures\objFile","objFolder\user.bmp",True (could not even test that part...)
THX in advance for your help.
i'm blocked for now
This post has been edited by r0sWell: 06 October 2009 - 08:38 AM



Help

Back to top









