从目录中选择随机文件 [英] Select random files out of a directory

查看:73
本文介绍了从目录中选择随机文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,目录中有10K个文件,


因为我不知道文件是否有名称,是否可以获取文件

随机?


谢谢。

for example, there are 10K files in the directory,

given that i don''t know if files name, is it possible to fetch a file
randomly?

thanks.

推荐答案

是......

参见opendir,readdir,rand

并获得创意

Hendri Kurniawan

howa写道:
Yes...
See opendir, readdir, rand
And get creative

Hendri Kurniawan
howa wrote:

例如,目录中有10K文件,


因为我不知道文件名是否为可以随机取一个文件

谢谢。
for example, there are 10K files in the directory,

given that i don''t know if files name, is it possible to fetch a file
randomly?

thanks.




Hendri Kurniawan?g1D?G

Hendri Kurniawan ?g1D?G

是......

参见opendir,readdir,rand

并且变得有创意


Hendri Kurniawan


howa写道:
Yes...
See opendir, readdir, rand
And get creative

Hendri Kurniawan
howa wrote:

例如,目录中有10K个文件,<鉴于我不知道文件是否有名称,是否可以随机取一个文件




谢谢。
for example, there are 10K files in the directory,

given that i don''t know if files name, is it possible to fetch a file
randomly?

thanks.



问题是:


文件夹中有太多文件,例如超过10K或者更多,我不想要b $ b想要列出它


但我知道它必须包含10K文件,所以有可能获得,

说这个文件夹下的第1020个文件?

the problem is:

there are too many files in the folder, e.g. over 10K or more, i don''t
want to list it

but i know that it must contains 10K files, so it is possible to get ,
say 1020th file under this folder?


>问题是:
>the problem is:

>文件夹中有太多文件,例如超过10K或更多,我不想列出它
但我知道它必须包含10K文件,所以有可能得到,说这个文件夹下的第1020个文件?
>there are too many files in the folder, e.g. over 10K or more, i don''t
want to list it
but i know that it must contains 10K files, so it is possible to get ,
say 1020th file under this folder?



使用scandir()返回文件名数组和array_rand()从该列表中选择一个

随机条目..(参见手册了解详情)


克里斯

Use scandir() to return an array of filenames and array_rand() to pick a
random entry from that list.. (see the manual for details)

Chris


这篇关于从目录中选择随机文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆