Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Renaming and moving files across drives w/ VB6

Status
Not open for further replies.

tyhand

Programmer
Jul 3, 2002
186
US

Anybody know of a routine, method or property to rename and move files across different drives?

I know about the fileSystemObject methods, but there's no rename method. Also know about the Name statement but you can't use it to rename across drives. VB.Net has a rename function for this, but I'm using VB 6 on Win98.

Any and all help is greatly appreciated.

Peace!

Thank
You
Have
A
Nice
Day!
 
Check out Shell32's SHFileOperation API call; this supports FO_RENAME
 
Did you try:

Name "C:\fred1.txt" As "D:\fred.txt"

It works for me on XP

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
thanks all.

Did try the name... as... statement, but it can't be used to rename across drives. At any rate, I'm looking into SHFileOperation. I found several references here on tek-tips. I just have to figure them out.

Peace!
 
First consider what a move call really does


First it copies then it deletes

I do this using the filesystem object

as such

set fs = filsystemobject

fs.copyfile oldname, newname

then I check to be sure all is well then

fs.deletefile dir & "\" filespec & "\" *.*"


Works for me quite well



this also allows you check that the directory etc exists and create it if not.




Using the file system object
 
Code:
FileCopy "C:\My Documents\Test.txt", "D:\Stuff\Foo.txt"[code]

Andy
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
"A computer program does what you tell it to do, not what you want it to do." -- Greer's Third Law
"Go Bengals!" -- Me
 
Public Sub MoveAndRename(CurrentFileLocation as String, NewFileLocation as String)

FileCopy CurrentFileLocation, NewFileLocation 'source , destination

Kill CurrentFileLocation 'if you want to delete the you are MOVING - remove i you want to COPY to a new location

End Sub


MoveAndRename "c:\Text1.txt", "E:\NewName.txt"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top