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


  1. Posts : 212
    Windows 7 Professional 64bit
       #1

    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?

    Thanks!

      My Computer


  2. Posts : 2,467
    Windows 7 Ultimate x64
       #2

    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 Computer


  3. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #3

    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


  4. Posts : 212
    Windows 7 Professional 64bit
    Thread Starter
       #4

    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 Computer


 

  Related Discussions
Our Sites
Site Links
About 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 09:10.
Find Us