Forum Discussion

sastowe's avatar
sastowe
Super Contributor
13 years ago

rename folder

Is there an bug in TC 7.2 that prevents a folder rename? I have this code:



  sPath = Project.Variables.sOutputRoot

  If aqFileSystem.Exists(sPath) Then

    sNewPath = aqFileSystem.ExcludeTrailingBackSlash(sPath) & Replace(Cstr(Now()), "/", "")

    sNewPath = Replace(sNewPath, ":", "")

    bSuccess = aqFileSystem.RenameFolder(sPath, sNewPath)    

  end if

  aqFileSystem.CreateFolder sPath 



bSuccess is returning false. The folder is not renamed. When I attempt to rename it in windows explorer, it renames fine. What am I doing wrong? Thanks



S
  • pmartin66's avatar
    pmartin66
    Occasional Contributor

     sPath = Project.Variables.sOutputRoot 





    that is not even valid code in 8.x (sOutputRoot is not a valid method)



    anyway, do some debug prints of sPath and sNewPath.



    do they have spaces? if so, they need quotes



    do they contain illegal characters, if so, fix... etc.



    otherwise, give me some code i can plunk into a new project and test so i can try to help.
  • Hello Stephanie,

    Adding more log messages especially during debugging helps. I'm guessing the problem is due to the following line removing the colon from the drive letter:

    sNewPath = Replace(sNewPath, ":", "")

    eg 'D:\Test' changes to 'D\Test'


    Also is the DateTimeToFormatStr function avaliable in 7.2? That way you won't have to do any replacing. Otherwise I'd suggest performing all the character replacements before concatenating as sNewPath. The following adds more log messages and DateTimeToFormatStr to get the date time format to be appended.



    Sub ForumFolderRename

      'sPath = Project.Variables.sOutputRoot

      sPath = aqFileSystem.ExcludeTrailingBackSlash("D:\Test\")

      If aqFileSystem.Exists(sPath) Then

         Log.Message("Folder Exists: " & sPath)     

         'sNewPath = aqFileSystem.ExcludeTrailingBackSlash(sPath) & Replace(Cstr(Now()), "/", "")

         strDate = aqConvert.DateTimeToFormatStr(aqDateTime.Now,"%m%d%y%H%M%S")

         sNewPath = aqFileSystem.ExcludeTrailingBackSlash(sPath) & strDate

         'sNewPath = Replace(sNewPath, ":", "")

         Log.Message("Rename folder to: " & sNewPath)

         bSuccess = aqFileSystem.RenameFolder(sPath, sNewPath)

         Log.Message("Rename Folder Successful: " & bSuccess)  

       end if

       aqFileSystem.CreateFolder sPath 

    End Sub


    Cheers,

    Jackson