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

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

问题描述

我需要为Windows操作系统,将选择特定文件夹中的随机文件的批处理文件,然后将该文件复制到不同的文件夹。我仍然需要该文件的一个副本留在原来的位置。

供参考,它需要一个批处理文件。

在此先感谢您的帮助...


解决方案

 关闭@echo
SETLOCAL EnableDelayedExpansion
CD \\特别\\文件夹
设定N = 0
在%% F(*。*)做(
   集/ A N + = 1
   设置文件[!N!= %% F

设置/ A兰特=(N *%随机%)/ 32768 + 1
拷贝!文件[%兰特%]! \\不同\\文件夹

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 \particular\folder
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%]!" \different\folder

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

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