Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report