bat產生隨機數並複製檔案及組建檔案列表

來源:互聯網
上載者:User

標籤:

有這樣一個情境:我需要將同一個檔案複製為上千個檔案,並且檔案名稱應為隨機數。為了簡單起見,不想寫程式,直接寫個BAT來,方便,簡單,易用:

1. 搞定用BAT產生32位隨機數,存為變數並使用,儲存以下代碼為rnd.bat:

 

@echo off
for %%i in ("0=A" "1=B" "2=C" "3=D" "4=E" "5=F")do set "x1%%~i"
setlocal enabledelayedexpansion
set "guid="
for /l %%i in (1,1,32)do (
set/a "n=!random!&15"
if !n! gtr 9 call set "n=%%x!n!%%"
set "guid=!guid!!n!")
set "guid=%guid:~,8%-%guid:~8,4%-%guid:~12,4%-%guid:~16,4%-%guid:~-12%"

copy a.jpg output\\%guid%.jpg

 

2.調用隨機數bat 1000次,儲存以下代碼為copyfile.bat

@echo off
rem echo "start"

for /L %%y in (1,1,1000) do ( call rnd.bat )

 

雙擊copyfile.bat即可複製a.jpg到output檔案夾下,每個檔案以隨機數命名。

 

 

附:複製之後,使用如下命令,產生output檔案夾複製後的檔案清單:

dir /b output>file_list.txt

bat產生隨機數並複製檔案及組建檔案列表

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.