Alan Abreu Absent Member.
Absent Member.
110 views

Renaming A File

Jump to solution
Is there some sort of function for renaming a file? I know I can just copy a file then delete the original if that's the only way.

- Thanks
0 Likes
1 Solution

Accepted Solutions
Cody Marcel Absent Member.
Absent Member.

Re: Renaming A File

Jump to solution
There are a few ways. The easiest off the top of my head is to issue the move shell command.

move file_oldname file_newname


http://www.easydos.com/move.html

View solution in original post

5 Replies
Rhonda Robinson Absent Member.
Absent Member.

Re: Renaming A File

Jump to solution
More details would be nice.

How are you attempting to rename a file? During an automated QTP script? If so, try using the system.util commands.

An attachment to a defect? Right click and select rename.

0 Likes
Cody Marcel Absent Member.
Absent Member.

Re: Renaming A File

Jump to solution
There are a few ways. The easiest off the top of my head is to issue the move shell command.

move file_oldname file_newname


http://www.easydos.com/move.html

View solution in original post

Highlighted
Alan Abreu Absent Member.
Absent Member.

Re: Renaming A File

Jump to solution
I was trying to rename a file via QTP. Should have mentioned that. The following did the trick:

Dim oShell
Set oShell = CreateObject ("WSCript.shell")
oShell.run "cmd /C rename c:\test.txt test2.txt"
Set oShell = Nothing

- Thanks
0 Likes
Cody Marcel Absent Member.
Absent Member.

Re: Renaming A File

Jump to solution
You can use move in the same fashion.

Dim oShell
Set oShell = CreateObject ("WSCript.shell")
oShell.run "cmd /C move c:\test.txt test2.txt"
Set oShell = Nothing

You can also open the file and do a SaveAs, but I think the shell is a much better option. It supports wild cards so you can hit several files at once if you need to.

Something like this...
move *.txt *.cvs
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.