[2008] Remove Chars from filenames

Worf

Member
Joined
Dec 19, 2008
Messages
15
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
 
Is this what you are looking for?

Code:
        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)
 
Is this what you are looking for?

Code:
        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
 
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

Doesnt work :(

Not removing characters
 
Back
Top