Create folder and subfolder structure using a loop…

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
suhascp
Posts: 14
Joined: 13 Nov 2021, 01:27

Create folder and subfolder structure using a loop…

Post by suhascp » 09 Dec 2022, 00:44

Hello,
if any one can crate code for given information its helps lot to me
actually i want a code like :
For example : have to create folder with name 100 - 199
next subfolder 100, 101, 102, 103,.... and so on till 199, series of number should take automatically.
inside subfolder 1,2,3 folders should be create.
it should be go on loop
Kindly help me on this.

User avatar
mikeyww
Posts: 26851
Joined: 09 Sep 2014, 18:38

Re: Create folder and subfolder structure using a loop…

Post by mikeyww » 09 Dec 2022, 05:15

Code: Select all

base = %A_ScriptDir%
Loop, 100 {
 dir := base "\100 - 199\" A_Index + 99
 Loop, 3 {
  FileCreateDir, % dir2 := dir "\" A_Index
  If ErrorLevel
   MsgBox, 48, Error, An error occurred when creating the directory.`n`n%dir2%
 }
}
MsgBox, 64, Done, Done!

suhascp
Posts: 14
Joined: 13 Nov 2021, 01:27

Re: Create folder and subfolder structure using a loop…

Post by suhascp » 09 Dec 2022, 06:53

Thank you mikeyww,
but actually i am using daily this code so
I need like insted of entering 100 - 199 in code, can we use in MSGBOX so we can enter other no's also like 200 - 299, 300 - 399..... and so on
and folder will create in some particular path, like this i need
100 - 199 - inside this
100 - Inside this
(Affected, Not Affected, Miscellaneous, Screenshots & Visio) these four folders
image.png
image.png (12.06 KiB) Viewed 562 times
i tried to write code by usings those code but i m not able to write, can you please help on this.

Actually for single folder i am using below code

" InputBox, LMtargetfolder
targetfolder = %LMtargetfolder%

FileCreateDir, %A_Desktop%\Order\%targetfolder%
FileCreateDir, %A_Desktop%\Order\%targetfolder%\Miscellaneous
FileCreateDir, %A_Desktop%\Order\%targetfolder%\Screenshots & Visio
FileCreateDir, %A_Desktop%\Order\%targetfolder%\Order Information
FileCreateDir, %A_Desktop%\Order\%targetfolder%\Not Affected
FileCreateDir, %A_Desktop%\Order\%targetfolder%\Affected
Return "

but i am not able to make loop and write code. PLease help me on this.

User avatar
mikeyww
Posts: 26851
Joined: 09 Sep 2014, 18:38

Re: Create folder and subfolder structure using a loop…

Post by mikeyww » 09 Dec 2022, 07:11

Your example has a fragmented description, and missing details. I am having trouble following all of it. Please write the complete steps in order:

1. InputBox appears. User enters (for example) ____________.
2. New folders named ______ are then defined.
3. If those folders already exist, then __________; otherwise, ____________.
4. Finally, subfolders named ____ are created.

Next time around, I would recommend providing the details in your initial post. Parsing the results of an inputbox are not part of the originally stated goal, and you also did not originally provide the subfolder names. These omissions would make coding the right script impossible. The omissions increase the time needed for you to get to what you want, and also needlessly add time for the coder.

suhascp
Posts: 14
Joined: 13 Nov 2021, 01:27

Re: Create folder and subfolder structure using a loop…

Post by suhascp » 09 Dec 2022, 07:23

if we run code
Steps :

1. InputBox : once we enter 100 - 199 then

2. Create (100 - 199) this folder

3. inside that 100, 101, 102, 103...... and so on till 199 sub folder will create

4. inside 100 , 101.... this four sub sub folders should create (Affected, Not Affected, Miscellaneous, Screenshots & Visio) for ever sub folders.
image.png
image.png (12.06 KiB) Viewed 494 times
like this

this the structure for code, please help me on this.

User avatar
Smile_
Posts: 858
Joined: 03 May 2020, 00:51

Re: Create folder and subfolder structure using a loop…

Post by Smile_ » 09 Dec 2022, 07:31

Small sample may help

2022-12-09_190754.png
Screenshot
2022-12-09_190754.png (26.91 KiB) Viewed 465 times

Code: Select all

Gui, Add, Edit, vWD w220 HwndE
EM_SetCueBanner(E, "Working directory...")
Gui, Add, Button,, Select

Gui, Add, Edit, vFrom Number w100 HwndE, 100
EM_SetCueBanner(E, "From...")

Gui, Add, Edit, vTo xp+120 Number w100 HwndE, 199
EM_SetCueBanner(E, "To...")

Gui, Add, Edit, xm vFolder w220 r5, % "Affected"
                                    . "`nNot Affected"
                                    . "`nMiscellaneous"
                                    . "`nScreenshots & Visio"
Gui, Add, Button, Disabled, Create
Gui, Show
ButtonSelect:
    FileSelectFolder, WD
    If (WD != "") {
        GuiControl,, WD, % WD
        GuiControl, Enable, Create
    }
Return

GuiClose:
ExitApp

ButtonCreate:
    GuiControlGet, WD
    GuiControlGet, From
    GuiControlGet, To
    GuiControlGet, Folder

    While (From <= To) {
        FileCreateDir, % WD "\" From
        Loop, Parse, Folder, `n, `r
            FileCreateDir, % WD "\" From "\" A_LoopField
        ++From
    }

    Msgbox, OK
Return

EM_SetCueBanner(Hwnd, Cue) {
    Return DllCall("User32.dll\SendMessage", "Ptr", Hwnd, "UInt", 0x1501, "Ptr", False, "WStr", Cue)
}

suhascp
Posts: 14
Joined: 13 Nov 2021, 01:27

Re: Create folder and subfolder structure using a loop…

Post by suhascp » 13 Dec 2022, 23:12

Thank you Smile_ :)
its helping me lot :)

Post Reply

Return to “Ask for Help (v1)”