samsmithnz Posted December 3, 2003 Posted December 3, 2003 I'm trying to do a fairly simple move of a file from one folder to another. But I'm having a little bit of trouble understanding the best way of handling it. Currently I have: Dim objFile As System.IO.File 'Move the file to a new location objFile.Move(strSourceFilePath, strTargetPath) The thing is I have a filename variable (holding "C:\projects\files\file.txt"), and I'd like to move it to another folder ("C:\projects"), but if the file already exists, I need to delete/overwrite it. The problem is I need to take the filename from the strSourceFilePath, and append it to the strTargetPath variable. I'm sure there used to be an easy way to drop the path and extract the file name in the old FileSystemObject... How do I do that in .NET (without using the split function, there must be a cleaner way) thanks Sam Quote Thanks Sam http://www.samsmith.co.nz
*Experts* Bucky Posted December 3, 2003 *Experts* Posted December 3, 2003 There most certainly is a cleaner way: Dim filename As String = System.IO.Path.GetFileName("c:\whatever.txt") Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
samsmithnz Posted December 3, 2003 Author Posted December 3, 2003 Excellent! thanks Bucky!. All my questions today were answered at the same time... Quote Thanks Sam http://www.samsmith.co.nz
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.