Run random script from a folder Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Unohdettu
Posts: 5
Joined: 27 May 2023, 00:44

Run random script from a folder

Post by Unohdettu » 28 May 2023, 00:27

Currently i'm trying to do so that every time i run my script it opens a random one between 3 files (or even more).

User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Run random script from a folder  Topic is solved

Post by mikeyww » 28 May 2023, 06:00

Code: Select all

#Requires AutoHotkey v1.1.33
dir := A_ScriptDir "\t"
fn  := ["1.txt", "2.txt", "3.txt"]
Random rnd, 1, fn.Length()
Run % dir "\" fn[rnd]

Unohdettu
Posts: 5
Joined: 27 May 2023, 00:44

Re: Run random script from a folder

Post by Unohdettu » 28 May 2023, 09:09

mikeyww wrote:
28 May 2023, 06:00

Code: Select all

#Requires AutoHotkey v1.1.33
dir := A_ScriptDir "\t"
fn  := ["1.txt", "2.txt", "3.txt"]
Random rnd, 1, fn.Length()
Run % dir "\" fn[rnd]
i don't quite understand the last part. what's supposed to be instead of "\"?

User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Run random script from a folder

Post by boiler » 28 May 2023, 09:43

Unohdettu wrote: i don't quite understand the last part. what's supposed to be instead of "\"?
Nothing is supposed to be instead of it. It’s meant to be exactly as shown. That’s the backslash between the directory and the file name.

Unohdettu
Posts: 5
Joined: 27 May 2023, 00:44

Re: Run random script from a folder

Post by Unohdettu » 28 May 2023, 10:16

it doesn't seem to work, it says couldn't find the file
image.png
image.png (41.58 KiB) Viewed 388 times

User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Run random script from a folder

Post by boiler » 28 May 2023, 10:21

The fn array isn't meant to contain full paths. It's meant to be file names that are in a sub-directory of the script's directory named "t". So you would put your three test files in a folder named "t" in the folder that your script is in.

Unohdettu
Posts: 5
Joined: 27 May 2023, 00:44

Re: Run random script from a folder

Post by Unohdettu » 28 May 2023, 10:28

boiler wrote:
28 May 2023, 10:21
The fn array isn't meant to contain full paths. It's meant to be file names that are in a sub-directory of the script's directory named "t". So you would put your three test files in a folder named "t" in the folder that your script is in.
thank you very much, now it works like a charm :O

User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Run random script from a folder

Post by mikeyww » 28 May 2023, 10:29

If your fn is meant to include the full path, then you will not need the dir at all. You would also need to specify the files themselves unless you want to use Loop Files to retrieve them. The bottom line is that you need to examine your script to understand what it is doing.

Post Reply

Return to “Ask for Help (v1)”