home bbs files messages ]

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

   alt.msdos.batch      Fun with MS-DOS batch files      42,547 messages   

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

   Message 41,050 of 42,547   
   foxidrive to noway   
   Re: batch move folders using wildcards?   
   20 Dec 14 08:16:21   
   
   From: foxidrive@server.invalid   
      
   On 20/12/2014 05:46, noway wrote:   
   > I can batch move files using wildcards. Like this:   
   > move aa*.* c:\files\a\aa   
   > but how can I move folders using wildcards?   
   > move aa* c:\folders\a\aa   
   > doesn't do the trick. Seems a basic thing to me, but I can't find a   
   > solution. Now I can't program; I can only adapt batch- and vbs-script.   
   >   
   > What I do now is copy folders called a to z and aa to zz (191 total) into   
   > the directory and manually move the folders aardvark to zebra into their   
   > folder aa to ze and all folders aa to az in the topfolder a, and so on...   
      
   This is a tool I use here to sort files or folders that are in the same   
   directory as the batch file,   
   by their first character.   
      
   You can launch it like this:   
      
   batch.bat d *           < sort all folders by first character   
   batch.bat d F*          < sort all folders starting with F by first character   
   batch.bat *.txt         < sort all text files by first character   
   batch.bat document*.txt < sort all text files starting with "document" by   
   first character   
   batch.bat d * "Shows "  < sort all folders by first character into folders   
   like below   
      
   Shows A   
   Shows B   
   Shows C   
   etc   
      
      
   I reduced my batch file to just this function and haven't tested to see if I   
   forgot something,   
   so test it first on copies of your files/folders.   
      
      
   @echo off   
      
   if "%~1"=="/?" "%~0"   
      
   if "%~1"=="" (   
   echo(Syntax: "%~nx0" [d] filespec.ext ["folder prefix"]   
   echo(  sorts files or directories by first character into folders   
   echo(   
   pause   
   goto :EOF   
   )   
      
   if /i "%~1"=="d" (   
   set "n=%~2"   
   set type="%~2" /a:d   
   set "prefix=%~3"   
   set d=d   
   ) else (   
   set "n=%~1"   
   set type="%~1" /a:-d   
   set "prefix=%~2"   
   )   
      
   for /f "delims=" %%a in ('dir %type% /b') do if exist "%%a" call :go "%%a"   
   if not defined self pause   
   goto :EOF   
      
   :go   
   if "%~1"=="%~nx0" goto :EOF   
   set "a=%~1"   
   set "a=%a:~0,1%"   
      
   set "b="   
   for %%z in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do if /i   
   "%%z"=="%a%" set "b=%%z"   
   if not defined b set "b=1"   
      
   echo moving %1   
   md "%prefix%%b%" 2>nul   
      
   if /i "%d%"=="d" (   
   move "%~1" "%prefix%%b%" >nul 2>&1   
   ) else (   
   move "%~n1.*" "%prefix%%b%" >nul 2>&1   
   )   
   goto :EOF   
      
   --- 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