DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Create Patterned Subdirectories, (Move Folders)  (Read 4,766 times)

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 563
Create Patterned Subdirectories, (Move Folders)
« on: May 28, 2020, 04:59 AM »
Brainstorming here before searching elsewhere for solutions.

Suppose we want to create the following folders:

c:\aaa
c:\aab
c:\aac
.
.
.
c:\baa
c:\bab
.
.
.
c:\zzx
c:\zzy
c:\zzz

If you following my drift, a-z in first column.  a-z second.  a-z third.

Total new subdirectories = 26*26*26 = 17,576

How might one go about accomplishing this?

(After doing the preceding, then time to move folders appropriately....  I'll turn to that later, perhaps.)

Thoughts appreciated.

Nicholas Kormanik

« Last Edit: May 28, 2020, 06:25 AM by nkormanik »

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 563
Re: Create Patterned Subdirectories, (Move Folders)
« Reply #1 on: May 28, 2020, 06:34 AM »
Appears Mathematica can do this, just about as well as any other way:

Tuples[{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}, 3]

So, next part of the question is how to move FOLDERS into those created subdirectories.  If first three letters of folder matches, move into the appropriate new subdirctory.

Example:

Existing folder is c:\abcdefg

Move said folder (and contents, of course) into c:\abc

Should be simple DOS command move c:\abcdefg c:\abc

Unfortunately, works for files.  Not folders....

Another matter arises when existing folder has only one or two characters.  Like c:\ab.

Hmmm....

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: Create Patterned Subdirectories, (Move Folders)
« Reply #2 on: May 28, 2020, 05:02 PM »
Here's an AutoHotkey solution for the first part:

Code: (AutoHotkey)
myDestFolder := "c:\tmp" ; Change this to suit.

myTuples := GetTuples( "abcdefghijklmnopqrstuvwxyz", 3 )

Loop, Parse, myTuples, `n, `r
{
    If ( A_LoopField )
    {
        FileCreateDir, % myDestFolder . "\" . A_LoopField
    }
}

/*
    GetTuples.ahk
    Copyright (C) 2010,2012,2013 Antonio Fran?a

    This script is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This script is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this script.  If not, see <http://www.gnu.org/licenses/>.
*/

;========================================================================
; 
; Function:     GetTuples (aka Arrange)
; Description:  Arranges a given input into all possible N-tuples
; URL (+info):  https://bit.ly/Sip44M
;
; Last Update:  02/February/2013 04:50 BRT
;
; Created by MasterFocus
; - https://github.com/MasterFocus
; - http://masterfocus.ahk4.net
; - http://autohotkey.com/community/viewtopic.php?f=2&t=88198
;
;========================================================================

GetTuples(p_List,p_Pick,p_InputD="",p_InputO=" `t",p_OutputDin=""
,p_OutputDout="`n",p_Reverse=0,p_Offset=0,p_Count=0,p_Func="",p_Valid=0) {
    If ( p_List = "" ) OR ( p_Pick < 1 )
        Return
    StringSplit, l_Arr, p_List, %p_InputD%, %p_InputO%
    Loop, %p_Pick%
        l_CharIndex%A_Index% := p_Reverse ? l_Arr0 : 1
    l_IsFunc := IsFunc(p_Func), p_Offset := Abs(p_Offset)
    If ( p_Count > (l_TotalTuples := l_Arr0 ** p_Pick) ) OR ( p_Count = 0 )
        p_Count := l_TotalTuples - p_Offset
    If ( p_Valid > l_TotalTuples ) OR ( p_Valid = 0 )
        p_Valid := p_Count
    Loop, %l_TotalTuples% {
        l_Result := ""
        Loop, %p_Pick%
            l_CharIndex := l_CharIndex%A_Index%, l_Result .= p_OutputDin l_Arr%l_CharIndex%
        Loop, %p_Pick% {
            l_Idx := p_Pick-(A_Index-1)
            If p_Reverse {
                If ( ( l_CharIndex%l_Idx% -= 1 ) >= 1 )
                    Break
                l_CharIndex%l_Idx% := l_Arr0
            }
            Else {
                If ( ( l_CharIndex%l_Idx% += 1 ) <= l_Arr0 )
                    Break
                l_CharIndex%l_Idx% := 1
            }
        }
        If ( A_Index-1 < p_Offset )
            Continue
        l_Result := SubStr(l_Result,1+StrLen(p_OutputDin)), l_Output .= l_IsFunc
            ? (((l_Dummy := %p_Func%(l_Result))<>"") ? (p_OutputDout l_Dummy, p_Valid--)
            : "") : (p_OutputDout l_Result, p_Valid--)
        If !( (--p_Count) AND p_Valid )
            Break
    }
    Return SubStr(l_Output,1+StrLen(p_OutputDout))
}

Some notes:

  • You cannot create three letter folders or files with the following names: aux, con, nul, & prn
  • The DOS move command _does_ work for folders.

What's the use case for the second part?

Original address: https://www.donationcoder.com/forum/index.php?topic=49965.0