home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   alt.msdos.batch.nt      Fun with Windows NT batch files      68,980 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 68,024 of 68,980   
   Zaidy036 to Andy Ho   
   Re: move a fixed number of files between   
   11 Mar 23 20:57:13   
   
   From: Zaidy036@air.isp.spam   
      
   On 3/10/2023 11:55 AM, Andy Ho wrote:   
   > On Sunday, May 7, 2017 at 2:37:12 PM UTC+7, Herbert Kleebauer wrote:   
   >> On 06.05.2017 18:49, hvd...@gmail.com wrote:   
   >>   
   >>>>> Eg: I have a folder A contains 100.000 files. I want to have a   
   >>>>> code that click one time move 5000 files from A to folder 1, 2, ..., 19,   
   20.   
   >>>>   
   >>>> @echo off   
   >>>> set SourceDir=C:\dir1   
   >>>> set TargetDir=C:\dir2   
   >>>> set MaxFiles=100   
   >>>>   
   >>>> set m=0   
   >>>> set n=0   
   >>>>   
   >>>> for /f %%i in ('dir /b /a-d "%SourceDir%\*.*"') do call :sub %%i   
   >>>> goto :eof   
   >>>>   
   >>>> :sub   
   >>>> if not %m%==0 goto :s1   
   >>>> set /a n=n+1   
   >>>> mkdir %TargetDir%\%n%   
   >>>> set m=%MaxFiles%   
   >>>>   
   >>>> :s1   
   I would make a versitile batch using START \MoveFiles.bat %1 %2   
      
   If always the same folders make a shortcut to the batch   
      
   %1 is source and %2 is destination so for you:   
       START \MoveFiles.bat "C:\dir1" "C:\dir2"   
   -   Note that %1 and %2 do not require " " if no spaces in them.   
   -   X: below represents any Full Path   
      
   :: File names from %1 into FilesToMove.txt   
   DIR /A:D /B %1 > X:\FilesToMove.txt   
      
   :: Count files in FilesToMove.txt   
   FOR /f %%A in ('X:\FilesToMove.txt ^| FIND /V /C ""') DO SET cnt=%%A   
      
   :: Limit or remove for all   
   IF %cnt% GTR 5000 SET cnt=5000   
      
   :: Use this for test runs and delete later if no problems   
   SET cnt=5   
      
   FOR /L %%t IN (1,1,%cnt%) DO (   
   SET /p OneFile=< X:\FilesToMove.txt   
   COPY %1\!OneFile! %2\   
   MORE +1 X:\FilesToMove.txt   
   )   
      
   EXIT   
      
   Loop explanation (no comments allowed in a loop)   
     - SET changes variable to first file name   
     - COPY does the work for test runs so change to MOVE if no problems   
     - MORE +1 removes the first file from X:\FilesToMove.txt   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca