Advertisement

05.09.2008 at 04:51AM PDT, ID: 23388965 | Points: 499
[x]
Attachment Details
Sorting-Order for CFileFind
Tags: c++, Vsual C++ 6.0
Hello Everyone!

I use the CFileFind-Function to get files in my Archiv-Folder and then make a String from the Date and the Name of the File and put this string  (like "31-12-06 10:30 Filename.doc") into a CStringArray. This way I get the alphabetical Order of the files. Is this alway like this? And what should i do to get the files in the last write date order? I know I could change the date format in the format "2007-12-31 10:30 Filename.doc" and then sort the list, but that is not so good readable. Is there a way to change the order I get the files from the FindFile Funktion? Like "dir /OD" in DOS? I could also use a differned Function.

Greedings

Sonja
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
CFileFind FSearcher;
  CString   cSearchFileName;
 
  cSearchFileName.Format(_T("%s\\*.*"), ArchivPath);
 
  if(FSearcher.FindFile( cSearchFileName ))
  {
    bool bFilesAvailable = TRUE;
 
    while( bFilesAvailable )
    {
      bFilesAvailable = FSearcher.FindNextFile();
      if (!FSearcher.IsDots())
      {
        CString csFName;
        CTime csFDate;
        FSearcher.GetLastWriteTime(csFDate);
        csFName.Format(_T("%s %s"),csFDate.Format(_T("%d-%m-%y %H:%M")), FSearcher.GetFileName());
 
        rNameList.Add( csFName );
      }
    }
  }
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: Sonja_M
Question Asked On: 05.09.2008
Participating Experts: 2
Points: 499
Views: 0
Translate:
Loading Advertisement...
05.09.2008 at 04:59AM PDT, ID: 21531876

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.09.2008 at 05:24AM PDT, ID: 21532020

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.09.2008 at 05:58AM PDT, ID: 21532289

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.09.2008 at 07:49AM PDT, ID: 21533403

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.15.2008 at 05:20AM PDT, ID: 21572651

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
05.09.2008 at 04:59AM PDT, ID: 21531876

Rank: Guru

You must order the file yourself. FileFind / FindNextFile doesn't order the files for you.
 
05.09.2008 at 05:24AM PDT, ID: 21532020
Hi alb66

Thanks for your answer.

I thought it might be so.

And is there any other similar function there i can get the result sortet? In my special case I anyway search for ALL files in the directory.

Greedings

Sonja
 
05.09.2008 at 05:58AM PDT, ID: 21532289

Rank: Guru

I don't know any API doing sort.
There is a project at
http://www.codeproject.com/KB/files/fileinfo.aspx
with a class that can retrieve and order files by size or by name, ascending or descending.
It should be very easy to add the capabilities of order by date with a little modify of AddFileInfo() method.
 
05.09.2008 at 07:49AM PDT, ID: 21533403

Rank: Genius

Using a 'std::list' (http://www.sgi.com/tech/stl/List.html) instead of a CStringArray makes sorting a opiece of cake, e.g.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
#include <list>
#include <string>
using namespace std;
 
vector<string> lNameList;
 
CFileFind FSearcher;
  CString   cSearchFileName;
 
  cSearchFileName.Format(_T("%s\\*.*"), ArchivPath);
 
  if(FSearcher.FindFile( cSearchFileName ))
  {
    bool bFilesAvailable = TRUE;
 
    while( bFilesAvailable )
    {
      bFilesAvailable = FSearcher.FindNextFile();
      if (!FSearcher.IsDots())
      {
        CString csFName;
        CTime csFDate;
        FSearcher.GetLastWriteTime(csFDate);
        csFName.Format(_T("%s %s"),csFDate.Format(_T("%d-%m-%y %H:%M")), FSearcher.GetFileName());
 
        lNameList.push_back( csFName );
      }
    }
  }
 
  lNameList.sort();
Open in New Window
 
05.15.2008 at 05:20AM PDT, ID: 21572651
@alb66: The Class you posted seems to be what I need. I will test it

@jkr: If I do it this way I would have to use the 2007-31-12 12:40 Format instead of the 31-12-2007 12:40 for the time, which I dont want to. But thanks for the tip - I could use that maybe on another location there the sorting is done by Hand.

Greedings

Sonya
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628