LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-31-2005, 09:08 PM   #1
purefan
Member
 
Registered: Aug 2003
Location: Sweden
Distribution: Ubuntu 10.04
Posts: 99

Rep: Reputation: Disabled
Getting File atributes in c++


heello!
im running VC++6 in Windows XP and...
I need to retrieve the file atributes from a variable number of files...atributes like last modified, size...
It is very important this since it is for a homework (for which I posted before but when I had a different issue).
I found on the MSDN something but works only under .NET framework and I dont have it...
Thank you soo much for the help
 
Old 04-01-2005, 02:40 AM   #2
alred
Member
 
Registered: Mar 2005
Location: singapore
Distribution: puppy and Ubuntu and ... erh ... redhat(sort of) :( ... + the venerable bsd and solaris ^_^
Posts: 658
Blog Entries: 8

Rep: Reputation: 31
have you tried

Code:
HANDLE FindFirstFile(LPCTSTR lpFileName, LPWIN32_FIND_DATA lpFindFileData);

BOOL FindNextFile(HANDLE hFindFile, LPWIN32_FIND_DATA lpFindFileData);

BOOL FindClose(HANDLE hFindFile);
the return values for lpFindFileData

typedef struct _WIN32_FIND_DATA {
DWORD dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
DWORD nFileSizeHigh;
DWORD nFileSizeLow;
DWORD dwReserved0;
DWORD dwReserved1;
TCHAR cFileName[ MAX_PATH ];
TCHAR cAlternateFileName[ 14 ];
} WIN32_FIND_DATA;

if working on single file then you can try
Code:
DWORD GetFileSize(   HANDLE hFile,  LPDWORD lpFileSizeHigh );
BOOL GetFileTime( HANDLE hFile, LPFILETIME lpCreationTime, LPFILETIME lpLastAccessTime, LPFILETIME lpLastWriteTime);
check your VC++ documentation for examples for these functions.
not sure these can work for you but be aware that your visual C++ might have simpler and faster "builtin" file handling functions.Better check your documentation

good luck to your homework

Last edited by alred; 04-01-2005 at 03:03 AM.
 
Old 04-01-2005, 10:05 AM   #3
purefan
Member
 
Registered: Aug 2003
Location: Sweden
Distribution: Ubuntu 10.04
Posts: 99

Original Poster
Rep: Reputation: Disabled
Great!!
well I managed to get the attributes I need in a very simple way:
Code:
	WIN32_FILE_ATTRIBUTE_DATA  wfad;

GetFileAttributesEx(TEXT("C:\\mybats\\pro.bat"), GetFileExInfoStandard, &wfad);

printf("Size of pro.bat is %u\n", wfad.ftLastWriteTime);
That is all!
simple as that, and while writting the wfad in the printf (for example) since this is a class at least in VC++6 it shows the functions withing that class, and so you are able to just get the size or other things you might want to retrieve. simple...yet not obvious, to me at least.
Thank for answering!!
 
Old 04-01-2005, 10:39 AM   #4
alred
Member
 
Registered: Mar 2005
Location: singapore
Distribution: puppy and Ubuntu and ... erh ... redhat(sort of) :( ... + the venerable bsd and solaris ^_^
Posts: 658
Blog Entries: 8

Rep: Reputation: 31
glad to hear that
things couldn't get any more simpler than that !!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
forrtl: severe (47): write to READONLY file, unit 5, file /dev/pts/1 terrence Programming 1 10-01-2005 10:22 PM
gave wrong syntax for tar as tar -cvzf file file.tgz how to recover the file gautham Linux - General 4 04-13-2005 03:15 AM
nfs a file shares ok via file mngr but not command line. Suse 9.1 acummings Linux - Networking 2 10-09-2004 02:23 PM
Yum update complains missing file (broken dep), but file can be located. davidas Linux - Software 0 03-27-2004 09:11 PM
How to play a media file/ video file/mp3 file recorded in harddisk/cd-rom arindam Linux - Newbie 2 09-05-2003 10:31 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration