Jump to content
Sign in to follow this  

help required for random file copy

Recommended Posts



I'm trying to make a random file copy script using AutoIt3.

The script should randomly copy a File from directory A1 and place it in directory B1 with the name background.jpg

The script that I tried is the following:

#cs ----------------------------------------------------------------------------

AutoIt Version:

Author: myName

Script Function:

Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

$filename = int(Random(1, 4))

$name = string ($filename) &".jpg"

FileCopy("C:\a1\$name", "C:\b1\background.jpg", 1)

What am I doing wrong and it is not copying the file ?

Please go easy because I'm new at this

Share this post

Link to post
Share on other sites

#include <file.au3>

$sourceFolder = "C:\temp"
 $destinationFolder = "C:\output"

$aFileList = _FileListToArray($sourceFolder, "*.*", 1)

$iRandom = Random(1,$aFileList[0],1)

FileCopy($sourceFolder & "\" & $aFileList[$iRandom],  $destinationFolder)

Edited by weaponx

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.