C# Sanitize File Name

前端 未结 12 1443
谎友^
谎友^ 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:26

    A shorter solution:

    var invalids = System.IO.Path.GetInvalidFileNameChars();
    var newName = String.Join("_", origFileName.Split(invalids, StringSplitOptions.RemoveEmptyEntries) ).TrimEnd('.');
    

提交回复
热议问题