Forum Discussion

rlagrouw's avatar
rlagrouw
New Contributor
9 years ago

aqFileSystem.CreateFolder returns true but didn't create folder

First of all, I'm using TestComplete 11.20.1491.7, I'm on Windows 7 Business 64 bit SP1 and I'm scripting with python.

 

When using environment variables in your path, aqFileSystem.CreateFolder returns true but the folder does not appear to be created.

 

Example: aqFileSystem.CreateFolder("%temp%\\folderName")

Result: Returns true, but no folder appears

 

Example: aqFileSystem.CreateFolder("C:\\Users\\lagrouw\\AppData\\Local\\Temp\\folderName")

Result: Returns true, folder appears

 

Same result for %systemdrive%, so it's not user-related (in case TestComplete runs as a different user for some reason)

 

I couldn't find a known issue on this and it's possible to work around it but it's really, really inconvenient. If i'm doing something i'm not supposed to or if there's something i can do to fix this i'd love to hear it!

 

  • Hi rlagrouw,

     

    aqFileSystem.CreateFolder does not support environment variables in paths. You need to use the path with all environment variables expanded:

    import os
    
    def Test():
        path = os.path.expandvars('%temp%\\MyFolder')
        aqFileSystem.CreateFolder(path) 
  • HKosova's avatar
    HKosova
    9 years ago

    rlagrouw wrote:

     

    I'm calling my function with a project variable (a string of course) as argument, like this:

    function(Project.Variables.myLocation)

    The project variable contains %TEMP%\myFolder\

     

    Doesn't work:

    def function(path):
       path = os.path.expandvars(path)

    Throws error "Invalid number of parameters".


    rlagrouw, can you try 11.3? I tried to repro the error but it works fine for me.

    11.3 includes some Python fixes and maybe a fix for this thing too.

  • baxatob's avatar
    baxatob
    Community Hero

    Hi rlagrouw,

     

    You can't call environment variable explicitly. You should use special TestComplete methods or constants.

     

    aqEnvironment.GetEnvironmentVariable("TEMP")  - will return the value of the  %TEMP% variable
    
    Sys.OSInfo.TempDirectory - will do the same

    More details here: https://support.smartbear.com/viewarticle/74192/

     

    • rlagrouw's avatar
      rlagrouw
      New Contributor

      baxatob That would indeed work but i'm using windows- style path strings as project variables which are used by code. Your solution would be hard to maintain if the path changes because they would reside in a script instead of the standardized location for variables.

       

      Nonetheless thanks for the reply, i'm sure it'll come in handy one day.

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Hi rlagrouw,

     

    aqFileSystem.CreateFolder does not support environment variables in paths. You need to use the path with all environment variables expanded:

    import os
    
    def Test():
        path = os.path.expandvars('%temp%\\MyFolder')
        aqFileSystem.CreateFolder(path) 
    • rlagrouw's avatar
      rlagrouw
      New Contributor

      HKosova Thanks for the reply, that seems to be partially a viable solution. 

       

      Works fine:

      path = os.path.expandvars("%TEMP%\\myFolder\\")

       

      I'm calling my function with a project variable (a string of course) as argument, like this:

      function(Project.Variables.myLocation)

      The project variable contains %TEMP%\myFolder\

       

      Doesn't work:

       

      def function(path):
         path = os.path.expandvars(path)

      Throws error "Invalid number of parameters".

       

      Does work:

      def function(path):
         path = os.path.expandvars(str(path))

       

      which is what i'll be using. Strange nonetheless (at least to me) but i'm glad it's a one-line solution to my problem! :smileyvery-happy:

      • HKosova's avatar
        HKosova
        SmartBear Alumni (Retired)

        rlagrouw wrote:

         

        I'm calling my function with a project variable (a string of course) as argument, like this:

        function(Project.Variables.myLocation)

        The project variable contains %TEMP%\myFolder\

         

        Doesn't work:

        def function(path):
           path = os.path.expandvars(path)

        Throws error "Invalid number of parameters".


        rlagrouw, can you try 11.3? I tried to repro the error but it works fine for me.

        11.3 includes some Python fixes and maybe a fix for this thing too.