Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • *Experts*
Posted

There most certainly is a cleaner way:

 

Dim filename As String = System.IO.Path.GetFileName("c:\whatever.txt")

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...