Announcement

Collapse
No announcement yet.

Create & check folders from variables/input

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Create & check folders from variables/input

    Hi!

    I'm new to AMS and I'm trying to build a small tool which creates several folders on a network share from user inputs.

    I currently use a batch script but want to switch to AMS.

    This is the current content of my batch:

    Code:
    set /p ordnernumber=Set order number (four digits: 0001, 0123, etc.):
    if exist \\MYSERVER\SHARE\%date:~-4%\18_%ordernumber%* ECHO WARNING! Order number already exists! &GOTO START
    In the first section the user has to enter a four digit order number. The script checks if this already exists.

    If the folder doesn't exist the user has to enter a description:

    Code:
    set /p projectdescription=Please enter a description
    After that the script continues and creates several folders and subfolders (20 pc) with mkdir from %ordernumber% and %projectdescription% on a network share.

    In AMS I created an input field (labeled orderno) with a #### input mask. Below this a xbutton which should check if the folder already exists. I created a variable for the network share:

    Code:
    _workingshare = "\\\\MYSERVER\\SHARE"
    I couldn't file any documentation about how to "expand" the Folder.DoesExist function in combination with the content from the input field.

    In the "On Click" event of the xbutton I placed

    Code:
    ordernotext = Input.GetText("orderno");
    to get the 4 digits from the input field. How can I combine this with my global _workingshare.. in Folder.DoesExist (if then)? And the next step would be to create the desired folders and subfolders from "ordernotext" inside "_workingshare.."


    Thx a lot for any help :-)

    Cheers

    CWT



  • #2
    It's a little tough following everything you've asked here - but I think I'm understanding your request. Before we get started though, let me just comment on this part of it:

    In AMS I created an input field (labeled orderno) with a #### input mask
    Yes, an input-mask is certainly the most straightforward way to limit the user to a 4-digit input. However, I'm going to suggest instead, using a standard input box (appropriately coded to achieve the same result). Reason being, is that I found the input-mask 'problematic' when trying to get a return on blank strings, whilst running a check against the user leaving the Input field blank. Not sure whether this is just a bug with my version of AMS (v8.0.7.0 Personal) or if it's actually a universal issue. So, I'll leave that one up to you.

    Anyhow, with that caveat, here's how I'd go about the whole thing.
    Check out the attached .Apz demo, noting the following:

    Globals:
    • In this example, your server-address is subbed for a local one (just for practicality and testing). Swap it out for your particular needs.

    Input Box (On Key):
    • Code employs e_Key event variable to ensure user enters ONLY numbers.
    • Ensure Input Box is set to "Standard", not to "Input Mask").

    xButton (On Click):
    • Ensures user doesn't leave Input field blank.
    • Ensures exactly 4 numbers are entered as Order No.
    • Grabs Order No. from Input field to create folder by that name (at path specified in Globals).
    • Runs check to see whether that folder already exists.


    Code's been quite thoroughly commented throughout, to minimize confusion.
    Nb. May have a bug or two - haven't checked it thoroughly yet. But should get you started.
    Attached Files

    Comment


    • #3
      Thank you very much for your help, time and effort in this! Very much appreciated :-)

      One last question: as described in my starting post, the users had to enter a description (if the ordner no doesn't exist). This description will be part of the "main" folder which is created.

      Example:

      1234_PROJECT_DESCRIPTION

      Maybe it's possible to combine the function of the xbutton (folder.doesexist after 4 digit input) with the input field. If the folder doesn't exist (or to be more precise: the first 4 digits followed by the description: \\\\MYSERVER\\SHARE\\1234_..........) the user has to enter the description. The xbutton would then "only" create the main folder followed by the desired subfolders.

      Again - thx a lot!

      Comment


      • #4
        Originally posted by cwt View Post
        ... One last question: as described in my starting post, the users had to enter a description (if the ordner no doesn't exist). This description will be part of the "main" folder which is created...
        Sure. The easiest way would be to create a 2nd Input field for the description. Then just append its variable to both the Folder.DoesExist() and Folder.Create() commands via standard concatenation convention. Modded example attached.

        Attached Files

        Comment


        • #5
          Wow, thank you

          One last dumb question: how can I add an underscore after the orderno when creating the folder? So that I receive \\<orderno>_<description>?

          Cheers

          Comment


          • #6
            Hi,
            Hope Bio doesn't mind me poking in
            It's quite simple where the space is place an underscore

            Code:
            .-- Create the folder (using value stored in "ordernotext" variable to name it)
                        Folder.Create(_workingshare.."\\"..ordernotext.."_"..description); -- Nb. You'd create whatever subFolders are required, by simply concatenating the relevant folder-paths here
                        Dialog.Message("Task Complete!", "Your folder has been successfully created at: " .. _workingshare);
                    end
            Cheers

            Comment


            • #7
              Originally posted by colc View Post
              It's quite simple where the space is place an underscore
              Yep, that worked

              Thank you @ all!

              Comment


              • #8
                Originally posted by colc View Post
                ...Hope Bio doesn't mind me poking in
                No problemo. The more the merrier!
                ......................................

                @cwt
                Just to elaborate / clarify what's actually happening in that line of code (xButton On Click - Line-19):

                The pair-of-dots (ie. '..') punctuation (which by default shows up as 'red' in your AMS code-editor) is the Lua concatenation symbol for joining string-values together. In your particular case, we're joining 3 string-values (comprised of):
                • 2 relative string-values (stored by the variables ordernotext & description)
                • 1 literal string-value (the underscore).
                ie. ordernotext + _ + description

                In written English, (obviously) we 'join' things with either the word 'and', or one of its common abbreviations (such as '&' or '+'.) But in Lua, we use the pair-of-dots symbol, instead. Hence, the above example becomes:

                ordernotext .. "_" .. description

                Note: The underscore is enclosed in quote-marks because it's a literal string (as opposed to ordernotext & description which are variables storing the value of relative strings).

                Comprehende?
                Yes, Bio - clear as mud!

                Comment


                • #9
                  BioHazard : muchas gracias

                  I still have a little problem with the folder.doesexist function in the script. I created 2 test folders with the script:

                  \\MYSERVER\SHARE\1234_abcdefg
                  \\MYSERVER\SHARE\2345_defgh

                  When I enter "1234" and "abcdefg" as orderno and description, the script throws up the warning (folder already exists). But when I enter "1234" as ordnerno again and "xyz" as description the script creates the folder. Can I use wildcards in

                  Code:
                  local bRet = Folder.DoesExist(_workingshare.."\\"..ordernotext.."_"..description);
                  after "..ordernotext.."? Or to be more precise: the script should only check the "ordernotext". I already tried

                  Code:
                  local bRet = Folder.DoesExist(_workingshare.."\\"..ordernotext);
                  but that didn't work.

                  Comment


                  • #10
                    Originally posted by cwt View Post
                    ... I already tried
                    Code:
                    local bRet = Folder.DoesExist(_workingshare.."\\"..ordernotext);
                    but that didn't work.
                    Corrrect - that won't work because it's instructing your app to look for folders named only with the Order No (and no Description appended).

                    Instead, you can employ the wildcard(*) symbol with the Folder.Find() function to return a table of paths for all folders beginning with the Order No. in their name. (And recurse through their subfolders too, if so desired). This would be used in place of the File.DoesExist() function.

                    Modded example attached. This should do the trick.


                    Attached Files

                    Comment


                    • #11
                      Great Job Bio , i found only one issue, its does not accept numbers from the numpad .

                      Comment


                      • #12
                        Another thing , it will give you that a folder is successfully Created even if its not created . If u put a non-exist path it will give you that a folder is created even the path is wrong or fake.
                        I tied your example apz but i didn't create any folder on the desktop as if its hidden because if tried to create the same folder name it tells you its already exists but you cant find it .

                        AMS 8.5.2 and Win10

                        Comment


                        • #13
                          Originally posted by sameer valva View Post
                          Great Job Bio , i found only one issue, its does not accept numbers from the numpad .
                          The action for restricting input to numbers-only is coded in the the On Key event of the 1st Input box. And uses the e_Key event variable to return input via Decimal representation of virtual key-codes. A list of virtual key-codes can be found in your manual under:
                          Contents >> Miscellaneous >> Virtual Key Codes

                          The virtual key-code range for NumPad characters (with Num Lock on) for 0-9 is: Decimal 96-105 inclusive. So you'd just add this range to your code in the On Key event of the 1st Input box. Try the attached mod (but remember to ensure that Num Lock on your keyboard is turned on):
                          Attached Files

                          Comment


                          • #14
                            I confirm its all working , it was Windows issue , i restart the system and it worked.

                            Thank u Bio

                            Comment


                            • #15
                              Originally posted by sameer valva View Post
                              Another thing , it will give you that a folder is successfully Created even if its not created .
                              That's exactly what it's supposed to do.


                              If u put a non-exist path it will give you that a folder is created even the path is wrong or fake.
                              How can you put in a non-existant path? The 1st Input field accept only a 4-digit code (representing the customer's Order No.) And the 2nd Input field is just an appended description determined by the user (which can be comprised of ANY character/s).


                              I tied your example apz but i didn't create any folder on the desktop as if its hidden because if tried to create the same folder name it tells you its already exists but you cant find it.
                              It tells you that a folder with same 4-digit Order No already exists, if it encounters any folder starting with that same 4-digit code (regardless of the Description appended via the 2nd Input field).

                              I've NO idea why you're getting 'hidden' output. Sounds like you might have a virus.

                              Comment

                              Working...
                              X