C # Remove the file prefix in batches. Recently, the software code generator is used, and the file name cannot be changed in the code.

Source: Internet
Author: User

[Csharp] static void Main (string [] args) {Console. writeLine ("this program removes the file prefix in the current directory and subdirectory"); Console. write ("Enter the prefix to remove:"); string stringFront = Console. readLine (); if (stringFront! = "") {String dir = AppDomain. CurrentDomain. BaseDirectory; RenameFile (dir, stringFront);} else Console. WriteLine ("Enter the prefix to remove! "); Console. writeLine ("Operation completed"); Console. readKey ();} public static void RenameFile (string ParentDir, string stringFront) {string [] files = Directory. getFiles (ParentDir ,"*. cs ", SearchOption. topDirectoryOnly); foreach (string file in files) {string filename = Path. getFileName (file); string pathname = Path. getDirectoryName (file); if (filename. startsWith (stringFront, true, null) {filename = filename. substring (stringFront. length); FileInfo fi = new FileInfo (file); fi. moveTo (Path. combine (pathname, filename);} string [] dirs = Directory. getDirectories (ParentDir); foreach (string dir in dirs) {RenameFile (dir, stringFront );}}

Related Article

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.