Get the App
SLTechnology News&Howtos  ›  Development  › 

C # how to get the specified files in the specified directory

Shulou Source: shulou.com Published: 2022-05-31 22:26:48 09月22日 Update

This article mainly introduces "how to get the specified files under the specified directory in C#". In the daily operation, I believe that many people have doubts about how to get the specified files in the specified directory. The editor has consulted all kinds of materials and sorted out the simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to get the specified files under the specified directory". Next, please follow the editor to study!

1. First, you need to specify the folder to get and the file name to get the file.

Folder: strLocalPath = System.Windows.Forms.Application.StartupPath + "\\ ExcelTemplate\"

File name: temp.xlsx

two。 Code:

ExecutionResult result = new ExecutionResult (); result.Status = true; string strLocalPath = System.Windows.Forms.Application.StartupPath + "\\ ExcelTemplate\"; if (Directory.Exists (strLocalPath)) {foreach (string GCFile in Directory.GetFiles (strLocalPath, "temp.xlsx", SearchOption.TopDirectoryOnly)) {string fileName = Path.GetFileName (GCFile); string filename = Path.GetFileName (GCFile) .replace (".xlsx", ") + DateTime.Now.ToString (" _ yyyyMMdd ") +" .xlsx " Try {File.Copy (strLocalPath + fileName, strLocalPath + "Temp\\" + filename, true); result = GetA31DayData (strLocalPath + "Temp\" + filename);} catch (Exception ex) {result.Status = false; result.Message = "copy file to destination file exception. Msg: "+ ex.Message; result.Anything = ex.Message; if (mesLog.IsErrorEnabled) {mesLog.Error (ex.StackTrace);} else {result.Status = false; result.Message =" Directory not exists! ";} return result; so far, the study on" how to get the specified files under the specified directory "is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Files directories folders Learning File names folders more help practical next Code articles methods Theory knowledge articles websites Materials follow questions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Xiaomi MySQL Redmi OPPO Reno