topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday March 29, 2024, 6:26 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

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

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 552
    • View Profile
    • Donate to Member
Create Patterned Subdirectories, (Move Folders)
« on: May 27, 2020, 11:59 PM »
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, 01:25 AM by nkormanik »

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 552
    • View Profile
    • Donate to Member
Re: Create Patterned Subdirectories, (Move Folders)
« Reply #1 on: May 28, 2020, 01: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

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,286
    • View Profile
    • Donate to Member
Re: Create Patterned Subdirectories, (Move Folders)
« Reply #2 on: May 28, 2020, 12:02 PM »
Here's an AutoHotkey solution for the first part:

Code: Autohotkey [Select]
  1. myDestFolder := "c:\tmp" ; Change this to suit.
  2.  
  3. myTuples := GetTuples( "abcdefghijklmnopqrstuvwxyz", 3 )
  4.  
  5. Loop, Parse, myTuples, `n, `r
  6. {
  7.     If ( A_LoopField )
  8.     {
  9.         FileCreateDir, % myDestFolder . "\" . A_LoopField
  10.     }
  11. }
  12.  
  13. /*
  14.     GetTuples.ahk
  15.     Copyright (C) 2010,2012,2013 Antonio Fran?a
  16.  
  17.     This script is free software: you can redistribute it and/or modify
  18.     it under the terms of the GNU Affero General Public License as
  19.     published by the Free Software Foundation, either version 3 of the
  20.     License, or (at your option) any later version.
  21.  
  22.     This script is distributed in the hope that it will be useful,
  23.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  24.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  25.     GNU Affero General Public License for more details.
  26.  
  27.     You should have received a copy of the GNU Affero General Public License
  28.     along with this script.  If not, see <http://www.gnu.org/licenses/>.
  29. */
  30.  
  31. ;========================================================================
  32. ;
  33. ; Function:     GetTuples (aka Arrange)
  34. ; Description:  Arranges a given input into all possible N-tuples
  35. ; URL (+info):  https://bit.ly/Sip44M
  36. ;
  37. ; Last Update:  02/February/2013 04:50 BRT
  38. ;
  39. ; Created by MasterFocus
  40. ; - https://github.com/MasterFocus
  41. ; - http://masterfocus.ahk4.net
  42. ; - http://autohotkey.com/community/viewtopic.php?f=2&t=88198
  43. ;
  44. ;========================================================================
  45.  
  46. GetTuples(p_List,p_Pick,p_InputD="",p_InputO=" `t",p_OutputDin=""
  47. ,p_OutputDout="`n",p_Reverse=0,p_Offset=0,p_Count=0,p_Func="",p_Valid=0) {
  48.     If ( p_List = "" ) OR ( p_Pick < 1 )
  49.         Return
  50.     StringSplit, l_Arr, p_List, %p_InputD%, %p_InputO%
  51.     Loop, %p_Pick%
  52.         l_CharIndex%A_Index% := p_Reverse ? l_Arr0 : 1
  53.     l_IsFunc := IsFunc(p_Func), p_Offset := Abs(p_Offset)
  54.     If ( p_Count > (l_TotalTuples := l_Arr0 ** p_Pick) ) OR ( p_Count = 0 )
  55.         p_Count := l_TotalTuples - p_Offset
  56.     If ( p_Valid > l_TotalTuples ) OR ( p_Valid = 0 )
  57.         p_Valid := p_Count
  58.     Loop, %l_TotalTuples% {
  59.         l_Result := ""
  60.         Loop, %p_Pick%
  61.             l_CharIndex := l_CharIndex%A_Index%, l_Result .= p_OutputDin l_Arr%l_CharIndex%
  62.         Loop, %p_Pick% {
  63.             l_Idx := p_Pick-(A_Index-1)
  64.             If p_Reverse {
  65.                 If ( ( l_CharIndex%l_Idx% -= 1 ) >= 1 )
  66.                     Break
  67.                 l_CharIndex%l_Idx% := l_Arr0
  68.             }
  69.             Else {
  70.                 If ( ( l_CharIndex%l_Idx% += 1 ) <= l_Arr0 )
  71.                     Break
  72.                 l_CharIndex%l_Idx% := 1
  73.             }
  74.         }
  75.         If ( A_Index-1 < p_Offset )
  76.             Continue
  77.         l_Result := SubStr(l_Result,1+StrLen(p_OutputDin)), l_Output .= l_IsFunc
  78.             ? (((l_Dummy := %p_Func%(l_Result))<>"") ? (p_OutputDout l_Dummy, p_Valid--)
  79.             : "") : (p_OutputDout l_Result, p_Valid--)
  80.         If !( (--p_Count) AND p_Valid )
  81.             Break
  82.     }
  83.     Return SubStr(l_Output,1+StrLen(p_OutputDout))
  84. }

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?