I need to randomly pick around 200 specific files from different sub folders to one folder. Following is the details:
"source_folder" contains "folder A", "folder B", "folder C"
folder A contain: module_01.x, module_02.x, module_03.x
folder B contain: module_01.x, module_02.x, module_03.x
folder C contain: module_01.x, module_02.x, module_03.x
I want to randomly pick 3 of them for example:
module_01.x from folder B
module_02.x from folder C
module_03.x from folder C
to "dest_folder".
Following is the code I am using but only shuttles a few and it seems always picking many files from only one folder and, when it trying to copy from another folder it won't overwrite the exist files(tried the /Y but no luck).
Any suggestions? Thank you very much!
@echo off&setlocal enabledelayedexpansion
set "source_folder=test"
set "dest_folder=output"
set /a filecount=193
del "dest_folder\*.x"
pushd "source_folder"
for /r %%i in (*.x) do set /a files+=1& set "$!files!=%%~i"
popd
pushd "dest_folder"
:randomloop
set /a rd=%random%%%files+1
set "sco=!$%rd%!"
if not defined x goto :randomloop
set "$%rd%="
for %%i in ("%x%") do if exist "%%~nxi" echo "%%~nxi" already exist in %out%.& goto:randomloop
copy "%x%" /Y
set /a filecount-=1
if %filecount% gtr 0 goto:randomloop
popd
pause
Aucun commentaire:
Enregistrer un commentaire