기본 콘텐츠로 건너뛰기

Directory FileName Sort



C#에서 Directory.GetFiles(<Path>) 에서 파일명으로 Sort를 할필요성이 있다.

Files 배열을 받아서 Sort를 할수도 있지만, Directory class 에서 Sort 기능도 제공을 하는데,

LINQ에 Sort 기능을 제공한다.

To sort by name,
var sorted = Directory.GetFiles(".").OrderBy(f => f);
To sort by size,
var sorted = Directory.GetFiles(".").OrderBy(f => new FileInfo(f).Length);

참고
  http://stackoverflow.com/questions/6294275/sorting-the-result-of-directory-getfiles-in-c-sharp

댓글

이 블로그의 인기 게시물

MongoDB 백업 및 복구방법

MongoDB 백업 및 복구방법 MongoDB 데이터 저장 디렉토리 설정(Windows) -> 보통 Default 로 "C:\data\db\" 로 지정되나, 혹시 디렉토리 설정을 바꿔서 모를경우에는 아래와 같이 명령어를 통해서 확인한다. mongodb --dbpath [arg-path] mongodb -v 명령어를 통해서 dbpath 경로를 확인할수 있다. local dump # mongodump -d [dbname] -o [dirname] Remote dump # mongodump --host mongodb1.example.net --port 37017 --username user --password pass /opt/backup/mongodump-2011-10-24 Mongorestore # mongorestore -h 127.0.0.1 "D\mongoDB\"

C# Namespace Naming Guidelines

The general rule for naming namespaces is to use the company name followed by the technology name and optionally the feature and design as follows. CompanyName.TechnologyName[.Feature][.Design] For example: Microsoft.Media Microsoft.Media.Design Prefixing namespace names with a company name or other well-established brand avoids the possibility of two published namespaces having the same name. For example,  Microsoft.Office  is an appropriate prefix for the Office Automation Classes provided by Microsoft. Use a stable, recognized technology name at the second level of a hierarchical name. Use organizational hierarchies as the basis for namespace hierarchies. Name a namespace that contains types that provide design-time functionality for a base namespace with the  .Design  suffix. For example, the  System.Windows.Forms.Design Namespace  contains designers and related classes used to design  System.Windows.Forms...