需要创建一个批处理文件从一个文件夹中选择一个随机文件并复制到另一个文件夹 [英] Need to create a batch file to select one random file from a folder and copy to another folder

查看:28
本文介绍了需要创建一个批处理文件从一个文件夹中选择一个随机文件并复制到另一个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为 Windows 操作系统创建一个批处理文件,该文件将从特定文件夹中选择一个随机文件,然后将该文件复制到另一个文件夹.我仍然需要该文件的副本才能保留在原始位置.

I need to create a batch file for Windows OS that will select a random file from a particular folder, then copy that file to a different folder. I still need a copy of that file to remain in the original location.

仅供参考,它需要是一个批处理文件.

FYI, it needs to be a batch file.

提前感谢您的帮助...

Thanks in advance for your help...

推荐答案

@echo off
setlocal EnableDelayedExpansion
cd particularfolder
set n=0
for %%f in (*.*) do (
   set /A n+=1
   set "file[!n!]=%%f"
)
set /A "rand=(n*%random%)/32768+1"
copy "!file[%rand%]!" differentfolder

这篇关于需要创建一个批处理文件从一个文件夹中选择一个随机文件并复制到另一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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