Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi again.

 

I have another problem that i need to solve to get my program to work correctly.

 

I need a routine or a couple of lines that will remove the following characters from filenames. These are Spaces, "." and "_" the one a found does not seem to work. :(

 

 

Many Thanks for you help

 

Worf

Posted

Is this what you are looking for?

 

       Dim FullPath As String = "C:\My_Dir\Just_A.File_Name.txt"
       Dim FileNameOnly As String = IO.Path.GetFileNameWithoutExtension(FullPath)
       FileNameOnly = Replace(FileNameOnly, "_", "")
       FileNameOnly = Replace(FileNameOnly, ".", "")
       FullPath = IO.Path.Combine(IO.Path.GetDirectoryName(FullPath), _
                   FileNameOnly & IO.Path.GetExtension(FullPath))
       Debug.Print(FullPath)

Posted
Is this what you are looking for?

 

       Dim FullPath As String = "C:\My_Dir\Just_A.File_Name.txt"
       Dim FileNameOnly As String = IO.Path.GetFileNameWithoutExtension(FullPath)
       FileNameOnly = Replace(FileNameOnly, "_", "")
       FileNameOnly = Replace(FileNameOnly, ".", "")
       FullPath = IO.Path.Combine(IO.Path.GetDirectoryName(FullPath), _
                   FileNameOnly & IO.Path.GetExtension(FullPath))
       Debug.Print(FullPath)

 

Hi JumpyNET

 

Thank you for your reply.

 

This looks like just what i need, if this works i can delete the routine that removes the extention as this routine will make things alot easier for me.

 

Many Thanks

 

Worf

Posted
Hi JumpyNET

 

Thank you for your reply.

 

This looks like just what i need, if this works i can delete the routine that removes the extention as this routine will make things alot easier for me.

 

Many Thanks

 

Worf

 

Doesn't work :(

 

Not removing characters

Posted
Could you please give an example string that you want to process. Or maybe a little of you current code.

 

It ok, got it working now.

 

Many Thanks

 

Worf

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...