Solved App to choose random files from a folder and copy/move it to another?

yankleber

IT Dinosaur
Member
VIP
Local time
6:28 AM
Messages
212
Location
Home
Hey all!

I think that the title says for itself...

I manage a group in Facebook with female illustrations (pinups, super-heroins, manga and art in general) and that I use to market a small online business of mine. I use to post around 20 pictures a day there and till the date I have chosen manually the picture set. At first it doesn't seem to be a lot of work but it becomes crazy as the collection gets bigger (mine is around 10 thousand and growing).

Because my lazy nature lately I have ended picking 20 of my favorite pictures among the first ones of the collection but I would like that the pictures were more random and totally independent of my personal taste.

I have found a small app called 'Pick me' that does almost what I need: it nicely selects 20 random files by the name and makes a list. However it is still crazy to run the list manually item by item and locate the files within a huge collection. Ideally the app should copy (or move) the selected files to a certain folder...

I was wondering if such app does exist?

Thanks!

:D
 

My Computer My Computer

At a glance

Windows 7 Professional 64bitIntel i5-33308GBOnboard
Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom
OS
Windows 7 Professional 64bit
CPU
Intel i5-3330
Motherboard
GigaByte B75M-D3H
Memory
8GB
Graphics Card(s)
Onboard
Sound Card
Behringer UCA222
Monitor(s) Displays
Samsung 22.5"
Screen Resolution
1920x1080
Hard Drives
SSD Kingston 120GB
HDD Samsung 320GB
Internet Speed
1M
Antivirus
ZoneAlarm FW + AV Free
Browser
Chrome

My Computer My Computer

At a glance

Windows 7 Ultimate x64Intel Core i7-740QM8 GB DDR3NVIDIA GeForce 330GT
Computer type
Laptop
Computer Manufacturer/Model Number
Toshiba Sattelite A665-S6092
OS
Windows 7 Ultimate x64
CPU
Intel Core i7-740QM
Memory
8 GB DDR3
Graphics Card(s)
NVIDIA GeForce 330GT
Screen Resolution
1366x768
Hard Drives
Samsung 840 SSD 500GB
1TB USB3 external HD
Cooling
Coolermaster Notepal U3 notebook cooling pad
Internet Speed
3mbps ASDL
Antivirus
ClamWin 0.98.7
Browser
Opera 12.17 x86 (main), Firefox 38 (sec), IE11 (last resort)
Hi Yankleber,

As Alejandro has suggested, a script is what you need and I have gone ahead and created one for you, Yankleber.


th-389858.bat
Code:
@echo off
setlocal EnableDelayedExpansion

set "source_path="    &REM Current directory is used if not defined
set "destination_path="    &REM Output is displayed on console if not defined
set "select=20"

goto :main

:get_random_integer Min Max [VarName]
setlocal
	set /a max=%~2, min=%~1
	set /a value=(MAX * %RANDOM%)/ 32768 + MIN
endlocal & if not "%~3"=="" ( set "%~3=%VALUE%" ) else ( set "value=%VALUE%" )
goto :eof

:get_random_lines TextFileName Amount
setlocal EnableDelayedExpansion
	if "%~2"=="" exit /b 1
	if "%~1"=="" exit /b 1
	for /f "delims=" %%I in ('type "%~1" ^| find /c /v ""') do set /a "n_lines=%%~I"
	if %~2 gtr %N_LINES% echo Selected number of files exceeds the number of avaliable files >&2&& exit /b 1
	set /a iter=0
	set "used_lines="
	:get_random_line__while
	set "pass=FALSE"
	call :get_random_integer 0 %N_LINES%
	if %VALUE% equ 0 (set "options="useback delims="") else (set "options="skip=%VALUE% useback delims="")
	for /f %OPTIONS% %%I in ("%~1") do (
		for %%J in (%USED_LINES%) do if "%%~J"=="%VALUE%" set "pass=TRUE"
		if /i !PASS!==FALSE (echo %%I)
		goto :break
	)
	:break
	if /i %PASS%==FALSE set /a iter+=1
	set "pass=FALSE"
	set "used_lines=%USED_LINES%,%VALUE%"
	if %ITER% lss %2 goto :get_random_line__while
endlocal
goto :eof

:main
pushd %SOURCE_PATH% 2>NUL || echo Source path does not exist&& exit /b 1
set "tempfile_files=%TEMP%\%~nx0_%RANDOM%.tmp"
if exist "%TEMPFILE_FILES%" del "%TEMPFILE_FILES%"
copy NUL "%TEMPFILE_FILES%" >NUL
for /f "delims=" %%I in ('dir /a:-d /b ^| findstr /vixc:"%~nx0"') do (>>"%TEMPFILE_FILES%" echo %%I)
if defined DESTINATION_PATH (
	set "destination_path=!DESTINATION_PATH:"=!"
	if not exist "%DESTINATION_PATH%" echo Destination path does not exist&& exit /b 1
	set "tempfile_rand=%TEMP%\%~nx0_2_%RANDOM%.tmp"
	if exist "!TEMPFILE_RAND!" del "!TEMPFILE_RAND!"
	copy NUL "!TEMPFILE_RAND!" >NUL
	call :get_random_lines "%TEMPFILE_FILES%" %SELECT% >>"!TEMPFILE_RAND!" || (
		del "%TEMPFILE_FILES%"
		del "!TEMPFILE_RAND!"
		exit /b 1
	)
	for /f "useback delims=" %%I in ("!TEMPFILE_RAND!") do (
		move "%%~I" "%DESTINATION_PATH%" >NUL
	)
	del "!TEMPFILE_RAND!"
) else (
	call :get_random_lines "%TEMPFILE_FILES%" %SELECT%
)
del "%TEMPFILE_FILES%"
popd
 

My Computer My Computer

At a glance

Windows 10, Windows 8.1 Pro, Windows 7 Profes...
Computer type
PC/Desktop
OS
Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
Hey Pyprohly!

It was more than perfect for what I needed! The only really small change I made is that I replaced the move command with copy. Other than that I didn't have to do anything else but to create a folder to where the files will be copied and declare it within your PERFECT script!

Thank you very much! I was really giving up about to find an application and was thinking about to write one myself in C# (but not very excited about this indeed).

You saved me a LOT!

Thank you! Thank you! Thank you! Thank you!

:D
 

My Computer My Computer

At a glance

Windows 7 Professional 64bitIntel i5-33308GBOnboard
Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom
OS
Windows 7 Professional 64bit
CPU
Intel i5-3330
Motherboard
GigaByte B75M-D3H
Memory
8GB
Graphics Card(s)
Onboard
Sound Card
Behringer UCA222
Monitor(s) Displays
Samsung 22.5"
Screen Resolution
1920x1080
Hard Drives
SSD Kingston 120GB
HDD Samsung 320GB
Internet Speed
1M
Antivirus
ZoneAlarm FW + AV Free
Browser
Chrome
Back
Top