Use C # To convert text files in batches to UTF-8

Source: Internet
Author: User

Currently, the source code of the program must be in the UTF8 format. Therefore, you need to convert the original source code. manual conversion is obviously too tired.

It's really easy to find c #, just a few lines of code. I tried converting GBK to UTF8 encoding format. It's okay.

Static void Main (string [] args)
{
String dir, filters;
Console. WriteLine ("Please input the directory :");
Dir = Console. ReadLine ();
Console. WriteLine ("Please input the filter (such as *. c, *. cpp ):");
Filters = Console. ReadLine ();
Console. WriteLine ("The following files will be converted :");
List <string> destfiles = new List <string> ();
Foreach (string filter in filters. Split (','))
{
Foreach (var eachfileinfo in new DirectoryInfo (dir). GetFiles (filter, SearchOption. AllDirectories ))
{
Destfiles. Add (eachfileinfo. FullName );
Console. WriteLine (eachfileinfo. FullName );
}
}
Console. WriteLine ("You Sure? (Y or n )");
String ans = Console. ReadLine ();
If (ans. Equals ("y", StringComparison. OrdinalIgnoreCase ))
{
Foreach (string destfile in destfiles)
{
File. WriteAllText (destfile, File. ReadAllText (destfile, Encoding. Default), Encoding. UTF8 );
}
Console. WriteLine ("finished .");
}
Else
{
Console. WriteLine ("Nothing changed .");
}
Console. WriteLine ("Press any key to exit .");
Console. ReadLine ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.