简体   繁体   中英

Find the name of a “New <File Type>” in C#

I'm making a program to automaticly move every file in a specific folder to my server, but I don't want my program to move "New files". But the problem is that the name of the file depends of the language of the coomputer and the type of file (For example: "New Text File" in english and "Nouveau Document Texte" in french) :/ Do anyone know if there is a way I could get this name in C# ?

EDIT: Here is my current code:

foreach (String file in Directory.GetFiles(@"C:\sendToBackup\"))
{
    extension = Path.GetExtension(file);
    fileName = Path.GetFileNameWithoutExtension(file);
    newF = @"Z:\Backups\" + fileName;
    if (!File.Exists(newF + extension))
    {
        File.Move(file, newF + extension);
    }
    else
    {
        File.Move(file, newF + $" ({count})" + extension);
    }
}

Thanks :)

Naming new files based on localization and culture settings is a feature of operating systems (MS Windows in your case), not a feature of programming Platforms (MS .Net) or programming languages (like C# and others). I think you can not find the solution in .Net & C#. In my opinion one feasible option is to find the meaning of "New Text File" in about 10 most probable languages you think your clients are using on their computers. Put these 10 lines in an enum or list and iterate them when you need to check for new file names.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM