Forum Discussion
Hi Luukdb!
After analyzing these functions a little more, I think I see what might be the issue.
The 'aqFileSystem.RenameFile' method is actually moving your files instead of copying them. So I suspect the error you are receiving is from the original file missing from the copy-from directory.
We can see the operation here in the description for this method = "If the NewPath parameter specifies another name of the folder, then this method moves and renames the file."
To correct this, I just altered your 'OldPath' variable to point to the copy-to directory instead of the copy-from.
var OldPath = "c:\\copyTo\\file1.txt";
var NewPath = "c:\\copyTo\\file1copy"+ timeNowFormatted + ".xml";
// Renames the file
aqFileSystem.RenameFile(OldPath, NewPath);
}
Here is the doc that covers the rename method so that you can see how it's working under the hood;
I hope this helps!
Hi Nick!
Thank you for you answer. For my understanding, do I need to create a folder copyTo?
I also noticed a problem with the aqfile.Copy method. For some reason he cannot find the path to copy the existing file. The location we use is a network harddisk and our Virtual Machine has access to this drive. And to my understanding it shouldn't be an issue but it keeps appearing that he can't find the files.
EDIT: I just found out that he can open the folder but when I add the document name to the path it's not possible for TestComplete and Windows to find the path.
EDIT 2: I might found the problem why TestComplete can't find the file to copy and rename.
The location where the file is stored is: \\bs-international.nl\group\ICT\Applicatiebeheer\TestComplete\NewPackingTable xml files
Because of the Javascript we need to use double \ for a folder to open. I added an extra \ in the code so it looks like this: \\bs-international.nl\\group\\ICT\\Applicatiebeheer\\TestComplete\\NewPackingTable xml files\\test.xml
But what I noticed is that the output TestComplete gives is this:
Hi Luukdb!
As for the 'copyTo' directory, that was just my example. You don't need to create a new directory, just rename the file with the 'renameFile' method from the same directory you are copying to, not from the original copy-from directory.
Full transparency I am not the most knowledgeable with JS, but a little googling on SO it looks like you can use 4 slashes for network drives, i.e. = \\\\bs-international.nl\group\ICT\Applicatiebeheer\TestComplete\NewPackingTable xml files\test.xml
Here is the SO I referenced = https://stackoverflow.com/questions/34837954/use-node-js-to-access-a-local-network-drive
And while this may not be an issue now, I notice there are spaces in the folder names, this can be a dangerous practice as handling spaces can be very difficult when writing code. I would highly recommend to replace any spaces in your folders/file names with an underscore (_). This will really help to avoid any issues down the road.
I hope all of this helps!