Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.

Windows 7: App to choose random files from a folder and copy/move it to another?

19 Jan 2016   #1

Windows 7 Professional 64bit
App to choose random files from a folder and copy/move it to another?

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?


My System SpecsSystem Spec
19 Jan 2016   #2

Windows 7 Ultimate x64

Is that generated list just a simple txt file with all the filenames inside?
If so, it's fairly easy to build a bat file to do the copy from the list:
scripting language - Batch: Copy a list (txt) of files - Stack Overflow
My System SpecsSystem Spec
20 Jan 2016   #3

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan

Hi Yankleber,

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

@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]
	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="
	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
	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
goto :eof

pushd %SOURCE_PATH% 2>NUL || echo Source path does not exist&& exit /b 1
set "tempfile_files=%TEMP%\%~nx0_%RANDOM%.tmp"
for /f "delims=" %%I in ('dir /a:-d /b ^| findstr /vixc:"%~nx0"') do (>>"%TEMPFILE_FILES%" echo %%I)
	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!"
	call :get_random_lines "%TEMPFILE_FILES%" %SELECT% >>"!TEMPFILE_RAND!" || (
		exit /b 1
	for /f "useback delims=" %%I in ("!TEMPFILE_RAND!") do (
		move "%%~I" "%DESTINATION_PATH%" >NUL
) else (
	call :get_random_lines "%TEMPFILE_FILES%" %SELECT%
My System SpecsSystem Spec

20 Jan 2016   #4

Windows 7 Professional 64bit

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!

My System SpecsSystem Spec

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

Thread Tools

Similar help and support threads
Thread Forum
Context Menu - Add Copy To Folder and Move To Folder
How to Add "Copy To Folder" and "Move To Folder" to Context Menu in Windows 7 and Windows 8 This tutorial will show you how to add or remove Copy To Folder and Move to Folder to the context menu for all users in Windows 7 and Windows 8. You must me logged in as an administrator to be able...
Unable to Move or Copy Some Files to a Folder
I have numerous family genealogy files/folders on a thumb drive that I want to copy to an existing folder on a HDD, but when I attempt the process it starts and stops at an annoying number of files that are reported to have file names that are too long. Even after I shorten them I still get the...
General Discussion
How to move/copy files together with it's folder
Hi everyone.. I am in a bit of trouble here. I have 1000+ collection of movies. All these movies are mixed, some are in SD format avi, and some in full HD mp4 format. All these movies are located under one folder, My Movies Collection. Underneath it, all the movies have their own respective...
General Discussion
Copy/Move to Folder
Is there a way I can change the Capitalization on that? I'm very anal about it and I don't like that it says Copy to folder, I'd like it to say Copy to Folder
Cannot move/copy files within folder
In Vista one could move files within a folder to whatever location manually simply by dragging the file to the desired location within the folder. In WIN7 everything seems to be locked and moving a file (for example image file) to the end of a row of other files within a folder won't work. How to...
General Discussion

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 07:47.
Twitter Facebook Google+