C# Sanitize File Name

前端 未结 12 1470
谎友^
谎友^ 2020-12-04 06:06

I recently have been moving a bunch of MP3s from various locations into a repository. I had been constructing the new file names using the ID3 tags (thanks, TagLib-Sharp!),

12条回答
  •  执念已碎
    2020-12-04 06:23

    I'm using the System.IO.Path.GetInvalidFileNameChars() method to check invalid characters and I've got no problems.

    I'm using the following code:

    foreach( char invalidchar in System.IO.Path.GetInvalidFileNameChars())
    {
        filename = filename.Replace(invalidchar, '_');
    }
    

提交回复
热议问题