Page 2 of 2

Re: Help ! Create new empty folders

Posted: 27 Jul 2010 13:10
by SkyFrontier
Is it possible for the code to simply append numbering when collision occurs? My no-GUI version throws a Windows message on not being possible to create an existing item... (It seems dumb when doing run tests, but picture what happens when you have to deal with a huge list with dozens of folders/files, locked on a "date modified" sorting...)
Thanks!

Re: Help ! Create new empty folders

Posted: 27 Jul 2010 15:21
by Stefan
Try this code.

I use just an HTML() Framework as standard GUI here:

Image



CreateSeries.xys

Code: Select all

//Example Framework for the XYplorer-script HTML() function

$InitialPath = "<curpath>";	

	$TextAreaDefault = "";  
      //$TextAreaDefault = "<clipboard>";

    $GETResult = utf8decode(html('<HTML>
    <BODY bgcolor="antiquewhite">
    <FORM method="GET" action="xys:">
    <TABLE width="99%" border="1" bgcolor="aquamarine">
    <TR><TD width="15%"><B>Description</B></TD><TD>&nbsp; Create series of new items         </TD></TR>
    <TR><TD>TextArea:</TD>                    <TD>&nbsp;                                     </TD></TR>
    <TR><TD>option 1-4:</TD>                  <TD>&nbsp;1: create folders    2: create files     3:       4:&nbsp;</TD></TR>
    <TR><TD>Option5:</TD>                     <TD>&nbsp; Text before                         </TD></TR>
    <TR><TD>Option6:</TD>                     <TD>&nbsp; start value                         </TD></TR>
    <TR><TD>Option7:</TD>                     <TD>&nbsp; max value                           </TD></TR>
    <TR><TD>Option8:</TD>                     <TD>&nbsp;  Text after                         </TD></TR>
    <TR><TD>Do it:</TD>                       <TD>&nbsp; Execute this script                 </TD></TR></TABLE>
    
    <TEXTAREA name="FormResult" rows=6 cols=75>' . $TextAreaDefault . '</TEXTAREA><BR>
    
    <INPUT type="radio" name="myOption" value="Option1" checked>  Option 1 &nbsp; 
    <INPUT type="radio" name="myOption" value="Option2"        >  Option 2 &nbsp;
    <INPUT type="radio" name="myOption" value="Option3"        >  Option 3 &nbsp;
    <INPUT type="radio" name="myOption" value="Option4"        >  Option 4 <BR>
    
     Option5: <input type="text" name="Option5" size="80" Value=""> <BR> 
     Option6: <input type="text" name="Option6" size="80" Value=""> <BR>
     Option7: <input type="text" name="Option7" size="80" Value=""> <BR>
     Option8: <input type="text" name="Option8" size="80" Value=""> <BR>
    
    <P align="right"><INPUT type="submit" name="Submit" value="Do it"> </P>
    </FORM>
    </BODY>
    </HTML>',"700", "630", "myWindowsTitle"));

   //get the results: 

   // IF you press the [Close]-button of the dialog 
   // instead of the [Submit]-button of the form or on an link,
   // then the result of HTML() is empty/nothing:
     IF ("$GETResult"=="") {sub "_Cancel";}

   // remove leading '?' from $GETResult content   
     substr $GETResult, $GETResult, 1; 

   //split the result into parts:
   //   split $GETResult into parts at the '&' sign and give me part N0. 1
   //   for example 'FormResult=textareacontent&myOption=Opt2&fname=J'...etc.
   //   becomes 'FormResult=textareacontent'
     $FormResult = gettoken($GETResult, "1", "&");

   // Then:
   // split $FormResult into parts at the '=' sign and give me part N0. 2
   // for example 'FormResult=textareacontent'
   // becomes 'textareacontent'
     $TextArea = urldecode(gettoken($FormResult, 2, "="));

   //now do the same for all other parts:
     $myOption = gettoken($GETResult, "2", "&");
     $myOption = urldecode(gettoken($myOption, 2, "="));
   //----
     $Option5 = gettoken($GETResult, "3", "&");
     $Option5 = urldecode(gettoken($Option5, 2, "="));
   //----
     $Option6 = gettoken($GETResult, "4", "&");
     $Option6 = urldecode(gettoken($Option6, 2, "="));
   //----
     $Option7 = gettoken($GETResult, "5", "&");
     $Option7 = urldecode(gettoken($Option7, 2, "="));
   //----
     $Option8 = gettoken($GETResult, "6", "&");
     $Option8 = urldecode(gettoken($Option8, 2, "="));


   //  
   //now do what you want with this results:
     msg "Content of the textarea is: $TextArea <crlf>
           Option 1-4 is: $myOption <crlf>
           Option5: $Option5 <crlf>
           Option6: $Option6 <crlf>
           Option7: $Option7 <crlf>
           Option8: $Option8 <crlf>",1;

  // YOUR script goes here:
  
    IF ($myOption == "Option1") {$ItemType   = "dir";}
    IF ($myOption == "Option2") {$ItemType   = "file";}
    $TextBefore = $Option5;
    $StartValue = $Option6;
    $MaxAmount  = $Option7;
    $TextAfter  = $Option8;
    
    
    $Count=1;
    while($Count<=$MaxAmount)
    {
    $Value = $StartValue -1 + $Count;
    while (strlen($Value)<strlen($StartValue)){$Value = 0$Value;}
    new $InitialPath\$TextBefore$Value$TextAfter , $ItemType;
    incr $Count;
    }
  

////////////////////////////////////////////////////////////////   
"_Cancel"
  msg "Cancled by user";   
	sub "_EOF";  
"_EOF"
	END 1==1;
//EOF
EDIT: added $InitialPath

Re: Help ! Create new empty folders

Posted: 27 Jul 2010 16:03
by SkyFrontier
Astonishing.
Worked great for both files and folders.
-files: IF told by user to do so (checkbox?), can they have an option to create out of any "base new item.ext", selected by user anywhere in the computer starting (default) from XY "NewItems" folder? Just an idea...
Item creation most of the times is not a mere question of what extension it has...
For me, it's better than I ever thought as it is!

Re: Help ! Create new empty folders

Posted: 28 Jul 2010 02:50
by SkyFrontier
Is it possible to make the script read original base files and reproduce their date/file attributes so I can artificially duplicate them at their empty folders counterparts? So I can easily browse them on huge lists, having at first sight their original timelines without having to look after the catalog from where they derive. Just a little idea (easy to implement, I believe) that will bring me a huge benefit I can't even think of until I saw the wonder at work. Anyway, THANKS!

Re: Help ! Create new empty folders

Posted: 05 Aug 2010 19:48
by Stefan
SkyFrontier wrote: side notice: if you click on the opposite panel, the script will continue to create folders in it,
so you must set the original pane as active again
Added $InitialPath:

$InitialPath = "<curpath>";
...
new $InitialPath\$TextBefore$Value$TextAfter , $ItemType;

Re: Help ! Create new empty folders

Posted: 05 Aug 2010 19:58
by SkyFrontier
Thanks, Stefan.
Will check that later - on a real scenario (script running with at least 500 folders to create). Currently can't do that - heavy load on CPU. Also, will test the "create files" instead of folders to see if this improves speed in a task as described in the original thread.
Will report a.s.a.p.
Thank you.