Ask a Question

unexpected result from aqFolderInfo.Rename

Howard
New Contributor

unexpected result from aqFolderInfo.Rename

I'm trying to use the aqFolderInfo.Rename function to rename folders on the local disk, but I'm getting some unexpected results. What I'm trying to do is simple: rename an existing folder c:\dirA as c:\dirAA. I'm using a script like:




      Set OrigFolder = aqFileSystem.GetFolderInfo(OrigDir)              

      if OrigFolder.Rename(NewDir) Then

        Log.Message("Directory " + OrigDir + " renamed as " + NewDir)

      else

        Log.Message("Failed to rename " + OrigDir + " as " + NewDir)        

      end if 




but with OrigDir set to "C:\dirA" and NewDir set to "C:\dirAA" (and starting with a directory C:\dirA containing only some files) I end up with c:\dirAA\dirA (containing the same files). I just want to simply rename the directory - what's going wrong? I've tried using the functions for the trailing slash, but these either have no effect or cause the rename to fail (e.g. with OrigDir set to "C:\dirA\" and NewDir set to "C:\dirAA\"). Thanks for any help.

 

(using TestComplete 7.51 on Vista 64)




Howard


5 REPLIES 5
Howard
New Contributor

RE: unexpected result from aqFolderInfo.Rename

NB replacing "OrigFolder.Rename(NewDir)" with "OrigFolder.Move(NewDir)" in the quoted script gives the same result, which makes sense for Move but not for Rename. Is this a bug with the Rename function?



Howard




RE: unexpected result from aqFolderInfo.Rename

Hi Howard,




Thank you for reporting the issue. Currently, we are investigating the situation.




In the meantime, you can use the Utilities.RenameFile method to rename a folder. Please see the "Utilities.RenameFile" help topic for details.

--
Dmitry Nikolaev

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Howard
New Contributor

RE: unexpected result from aqFolderInfo.Rename

Thanks for the feedback. Do you have any further info on progress in tracking down or solving this issue?



I'm currently using the Utilities.RenameFile as suggested, but this doesn't seem to work reliably. For example, when trying to rename "C:\dirA" to "C:\dirB", it sometimes fails - even when I confirm (before doing the rename) that "C:\dirA" exists and "C:\dirB" does NOT exist. Are there other reasons it could fail? Currently it works on some test runs, but fails a few times in others, with identical starting conditions.




Howard

Howard
New Contributor

RE: unexpected result from aqFolderInfo.Rename

I've come across some other problems with file/folder functions. I've been using aqFileSystem.GetFolderInfo to check whether a folder path (string) corresponds to an actual folder or not. I use something like:



Set folder_obj = aqFileSystem.GetFolderInfo(folder_path)

if folder_obj Is Not Nothing Then

  Log.Message("Folder name: " + folder_obj.name)

else

  Log.Error("Not a valid folder")

end if



If folder_path is set to something like "c:\temp\file.txt" I was expecting this to trigger the error, but it runs fine and returns "file.txt" as the folder name. Is this expected behaviour? How else can I check that a folder path corresponds to a valid folder?



thanks,



Howard


RE: unexpected result from aqFolderInfo.Rename

Hi Howard,




A fix for the Rename method related issue will be included in the next major version of the product.




As for checking whether a path to a folder is valid, we'll improve this behavior in one of future versions. In the meantime, you can use the following workaround:




Log.Message(aqFileSystem.CheckAttributes(folder_path, aqFileSystem.faDirectory) & aqFileSystem.Exists(folder_path));

--
Dmitry Nikolaev

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
cancel
Showing results for 
Search instead for 
Did you mean: