6 Replies Latest reply on Aug 4, 2014 8:29 AM by kanaga kumar

    Create folder hierarchy

    Dapeamel Level 1

      Hello all!

      I need a function that creates folders,

       

       

      create folder A on target "C:/test/123/"

      if folder A exists on target "C:/test/123/" then create folder B on target "C:/test/123/"

      if folder B don't exists on target "C:/test/123/" then create folder B on target "C:/test/123/"

      if folder B exists then create folder C on target "C:/test/123/"

       

      Could someone help me with this function

       

      Thank you in advance

        • 1. Re: Create folder hierarchy
          Chinnadk Level 4

          Try this,

           

          var target = Folder.selectDialog("Choose a target folder");
          if(!(Folder(target+"/"+"Folder A")).exists)
          {
                  new Folder(target + "/" + "Folder A").create();
              }
          else if(!(Folder(target+"/"+"Folder B")).exists)
          {
                  new Folder(target + "/" + "Folder B").create();
              }
          else if(!(Folder(target+"/"+"Folder C")).exists)
          {
                  new Folder(target + "/" + "Folder C").create();
              }
          else
          {
                  new Folder(target + "/" + "Folder D").create();
              }
          

           

          Regards,

          Chinna

          • 2. Re: Create folder hierarchy
            Dapeamel Level 1

            Thank you very much Chinna,

            • 3. Re: Create folder hierarchy
              kanaga kumar Level 1

              Dear Chinna,

               

              I need create subfolders from folder A, please see the screen shot for more details:

               

              Screen Shot 2014-08-02 at 2.11.27 PM.png

              Thanks in advance

              kanaga kumar. k

              • 4. Re: Create folder hierarchy
                Johnwhite Level 1

                Hi Chinna

                 

                Create a folder hierarchy is a very good idea, but

                 

                can you add some function?

                 

                I try to change it into this:

                 

                but I don't know how to make it works?

                 

                //==============================================================================

                 

                var

                  mySelected = Number( app.extractLabel("Choose a target folder") ),

                  myDialog = app.dialogs.add({name:"Create a folder hierarchy",canCancel:true});

                  with(myDialog){

                       with(dialogColumns.add()){

                           with(dialogRows.add()){

                                     staticTexts.add({staticLabel:"Please select a target folder for create a folder and sub folder hierarchy"});

                            with(dialogRows.add()){

                                 var

                                 mySelection = dropdowns.add({stringList:["01   Annual Report", "02   Interim Report", "03   Announcement", "04   Circular", "05   IPO"], selectedIndex: 0});

                                 }

                            }

                       }

                  }

                 

                 

                if (myDialog.show() == true) {

                    var docs = app.documents;

                    main();

                    myDialog.destroy();

                    }

                 

                if((Folder(target).exists)  // if folder exist aleart

                {

                      alert("exist")

                    }

                 

                    else {

                        cfh();

                    }

                 

                 

                function cfh(){

                    if (mySelection.selectedIndex == 0){ // Credate a new folder in the location of Annaul Report by type in the new name: (type in name by myself)

                 

                var the_dialog = app.dialogs.add({name:"Credate folders"});

                with(the_dialog.dialogColumns.add()){

                    with(dialogRows.add()){

                        staticTexts.add({staticLabel:"Please Type in New floder's name:"});

                        var grep_string = textEditboxes.add({minWidth:200});

                    }

                }

                the_dialog.show();

                 

                        new Folder("~/Annual Report" + "/" + "//this place for type new folder's name by myself").create();

                              }

                          }

                 

                 

                    if (mySelection.selectedIndex == 1){ // Credate a new folder in the location of Interim Report by type in the new name: (type in name by myself)

                 

                var the_dialog = app.dialogs.add({name:"Credate folders"});

                with(the_dialog.dialogColumns.add()){

                    with(dialogRows.add()){

                        staticTexts.add({staticLabel:"Please Type in New floder's name:"});

                        var grep_string = textEditboxes.add({minWidth:200});

                    }

                }

                the_dialog.show();

                 

                        new Folder("~/Interim Report" + "/" + "//this place for type new folder's name by myself").create();

                              }

                          }

                 

                 

                    if (mySelection.selectedIndex == 2){ // Credate a new folder in the location of Announcement by type in the new name: (type in name by myself)

                 

                var the_dialog = app.dialogs.add({name:"Credate folders"});

                with(the_dialog.dialogColumns.add()){

                    with(dialogRows.add()){

                        staticTexts.add({staticLabel:"Please Type in New floder's name:"});

                        var grep_string = textEditboxes.add({minWidth:200});

                    }

                }

                the_dialog.show();

                 

                        new Folder("~/Announcement" + "/" + "//this place for type new folder's name by myself").create();

                              }

                          }

                 

                    if (mySelection.selectedIndex == 3){ // Credate a new folder in the location of Circular by type in the new name: (type in name by myself)

                 

                var the_dialog = app.dialogs.add({name:"Credate folders"});

                with(the_dialog.dialogColumns.add()){

                    with(dialogRows.add()){

                        staticTexts.add({staticLabel:"Please Type in New floder's name:"});

                        var grep_string = textEditboxes.add({minWidth:200});

                    }

                }

                the_dialog.show();

                 

                        new Folder("~/Circular" + "/" + "//this place for type new folder's name by myself").create();

                              }

                          }

                 

                    if (mySelection.selectedIndex == 4){ // Credate a new folder in the location of IPO by type in the new name: (type in name by myself)

                 

                var the_dialog = app.dialogs.add({name:"Credate folders"});

                with(the_dialog.dialogColumns.add()){

                    with(dialogRows.add()){

                        staticTexts.add({staticLabel:"Please Type in New floder's name:"});

                        var grep_string = textEditboxes.add({minWidth:200});

                    }

                }

                the_dialog.show();

                 

                        new Folder("~/IPO" + "/" + "//this place for type new folder's name by myself").create();

                              }

                          }

                 

                }

                 

                var f = Folder("~/??/??/" );  //and then open what I create

                f.execute();

                 

                //==============================================================================

                 

                Can you make it work?

                 

                Thanks

                 

                John

                • 5. Re: Re: Create folder hierarchy
                  Chinnadk Level 4

                  Hi Kanaga kumar,

                   

                  Try this.

                   

                  var target = Folder.selectDialog("Choose a target folder");  
                  if(!(Folder(target+"/"+"Folder A")).exists)  
                  {  
                          new Folder(target + "/" + "Folder A").create();
                          new Folder(target + "/" + "Folder A" + "/Test1").create();
                          new Folder(target + "/" + "Folder A" + "/Test2").create();
                          new Folder(target + "/" + "Folder A" + "/Test3").create();
                      }  
                  else if(!(Folder(target+"/"+"Folder B")).exists)  
                  {  
                          new Folder(target + "/" + "Folder B").create();  
                          new Folder(target + "/" + "Folder B" + "/Test1").create();
                          new Folder(target + "/" + "Folder B" + "/Test2").create();
                          new Folder(target + "/" + "Folder B" + "/Test3").create();
                      }  
                  else if(!(Folder(target+"/"+"Folder C")).exists)  
                  {  
                          new Folder(target + "/" + "Folder C").create();  
                          new Folder(target + "/" + "Folder C" + "/Test1").create();
                          new Folder(target + "/" + "Folder C" + "/Test2").create();
                          new Folder(target + "/" + "Folder C" + "/Test3").create();
                      }  
                  else  
                  {  
                          new Folder(target + "/" + "Folder D").create();  
                          new Folder(target + "/" + "Folder D" + "/Test1").create();
                          new Folder(target + "/" + "Folder D" + "/Test2").create();
                          new Folder(target + "/" + "Folder D" + "/Test3").create();
                      }  
                  

                   

                  Regards,

                  Chinna

                  • 6. Re: Create folder hierarchy
                    kanaga kumar Level 1

                    Thanks for your coding chinna.

                     

                    Thanks

                    kanaga kumar. k