473,788 Members | 2,855 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help required on Extracting File Information

Hi..
I am stuck with a problem where I need to extract some information from
a File in C++.e.g File size,date of creation, Location on the Disk etc.
I haven't been able to find any particular solution yet. Could anybody
amongst you help me in this regard. I'll be glad.
Regards;
Saleem

Dec 21 '06 #1
6 2183

<sa***********@ gmail.comwrote in message
news:11******** **************@ 48g2000cwx.goog legroups.com...
Hi..
I am stuck with a problem where I need to extract some information from
a File in C++.e.g File size,date of creation, Location on the Disk etc.
I haven't been able to find any particular solution yet. Could anybody
amongst you help me in this regard. I'll be glad.
None of what you want to do is directly doable with
Standard C++, the topic here. You can come reasonably
close to 'file size', in that you can determine how
many characters (i.e. bytes) can be read from a file,
which might or might not exactly correlate to your
operating system's notion of 'file size'.

All the rest, you'll need to use features of your
operating system, some or all of which are likely
provided as extensions to your implementation' s
library.

Check your documentation, and/or support resources
devoted to your implementation and/or operating system.

-Mike
Dec 21 '06 #2
sa***********@g mail.com wrote:
Hi..
I am stuck with a problem where I need to extract some information from
a File in C++.e.g File size,date of creation, Location on the Disk etc.
I haven't been able to find any particular solution yet. Could anybody
amongst you help me in this regard. I'll be glad.
This is not possible in Standard C++ without using platform specific
libraries.

May I suggest that you ask in a newsgroup dedicated to your platform.

http://www.parashift.com/c++-faq-lit...t.html#faq-5.9
Dec 21 '06 #3
sa***********@g mail.com wrote:
I am stuck with a problem where I need to extract some information
from a File in C++.e.g File size,date of creation, Location on the
Disk etc. I haven't been able to find any particular solution yet.
Could anybody amongst you help me in this regard. I'll be glad.
Somebody in the newsgroup dedicated to your OS should be able to
help you. Things like file date, etc. are OS-specific. You could
try opening the file, positioning your stream to the end of the
file and getting the offset, thus obtaining the size of the file,
but that's about as much as you can do in Standard C++.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Dec 21 '06 #4
r
sa***********@g mail.com wrote:
Hi..
I am stuck with a problem where I need to extract some information from
a File in C++.e.g File size,date of creation, Location on the Disk etc.
I haven't been able to find any particular solution yet. Could anybody
amongst you help me in this regard. I'll be glad.
Regards;
Saleem
There is a filesystem library in boost that does some of the things you
need.

Dec 22 '06 #5
sa***********@g mail.com wrote:
Hi..
I am stuck with a problem where I need to extract some information from
a File in C++.e.g File size,date of creation, Location on the Disk etc.
I haven't been able to find any particular solution yet. Could anybody
amongst you help me in this regard. I'll be glad.
Regards;
Saleem
Try recls (http://synesis.com.au/software/recls/). Its a recursive sile
sytem search library, cross-platform. You can set up a search and read
off the matches one at a time, using Iterator-like object, or using STL
container-like object.
To getting the details of a single file you write something like the
following:
#include <recls/cpp/filesearch.hpp>

int main(int argc, char **argv)
{
if(argc < 2)
{
return EXIT_FAILURE;
}

using namespace recls::cpp;
using namespace std;

FileEntry entry = FileSearch::Sta t(argv[1]);

It gives you full information on path and components, including
absolute, and relative to the search directory.

cout << "full path: " << entry.GetPath() << endl;
cout << "search-relative path: " << entry.GetSearch RelativePath()
<< endl;
cout << "location: " << entry.GetDirect oryPath() << endl;
#ifdef RECLS_PLATFORM_ API_WIN32
cout << "drive: " << entry.GetDrive( ) << endl;
#endif
cout << "directory: " << entry.GetDirect ory() << endl;
cout << "file name+extension: " << entry.GetFile() << endl;
cout << "file name: " << entry.GetFileNa me() << endl;

/// and so on

One problem is that the size type is platform specific. So:

if(!entry.IsDir ectory())
{
#ifdef RECLS_PLATFORM_ API_WIN32
// recls_filesize_ t is ULARGE_INTEGER

cout << "size: " << entry.GetSize() .LowPart << endl;
#else
// recls_filesize_ t is off_t

cout << "size: " << entry.GetSize() << endl;
#endif

The same problem (but) worse!) is that the time type is platform
specific. So:
#ifdef RECLS_PLATFORM_ API_WIN32
// recls_time_t is FILETIME

// you have to convert using FileTimeToSyste mTime
FILETIME t1 = entry.GetCreati onTime();
FILETIME t2 = entry.GetModifi cationTime();
FILETIME t3 = entry.GetLastAc cessTime();
FILETIME t4 = entry.GetLastSt atusChangeTime( );
#else
// recls_time_t is time_t

// you have to convert using gmtime
time_t t1 = entry.GetCreati onTime();
time_t t2 = entry.GetModifi cationTime();
time_t t3 = entry.GetLastAc cessTime();
time_t t4 = entry.GetLastSt atusChangeTime( );
#endif

If you have a cross-platform time class you can just convert to your
time class and not worry about it. Date/time is such a drag. recls
seems to just ignore the problema dn leave it to the user.

If you can get round the time/size hasslles, it's otherwise good. I use
it for recusrive searches whenever I need it.

Dec 23 '06 #6

JimB wrote:
sa***********@g mail.com wrote:
Hi..
I am stuck with a problem where I need to extract some information from
a File in C++.e.g File size,date of creation, Location on the Disk etc.
I haven't been able to find any particular solution yet. Could anybody
amongst you help me in this regard. I'll be glad.
Regards;
Saleem

Try recls (http://synesis.com.au/software/recls/). Its a recursive sile
sytem search library, cross-platform. You can set up a search and read
off the matches one at a time, using Iterator-like object, or using STL
container-like object.
To getting the details of a single file you write something like the
following:
#include <recls/cpp/filesearch.hpp>

int main(int argc, char **argv)
{
if(argc < 2)
{
return EXIT_FAILURE;
}

using namespace recls::cpp;
using namespace std;

FileEntry entry = FileSearch::Sta t(argv[1]);

It gives you full information on path and components, including
absolute, and relative to the search directory.

cout << "full path: " << entry.GetPath() << endl;
cout << "search-relative path: " << entry.GetSearch RelativePath()
<< endl;
cout << "location: " << entry.GetDirect oryPath() << endl;
#ifdef RECLS_PLATFORM_ API_WIN32
cout << "drive: " << entry.GetDrive( ) << endl;
#endif
cout << "directory: " << entry.GetDirect ory() << endl;
cout << "file name+extension: " << entry.GetFile() << endl;
cout << "file name: " << entry.GetFileNa me() << endl;

/// and so on

One problem is that the size type is platform specific. So:

if(!entry.IsDir ectory())
{
#ifdef RECLS_PLATFORM_ API_WIN32
// recls_filesize_ t is ULARGE_INTEGER

cout << "size: " << entry.GetSize() .LowPart << endl;
#else
// recls_filesize_ t is off_t

cout << "size: " << entry.GetSize() << endl;
#endif

The same problem (but) worse!) is that the time type is platform
specific. So:
#ifdef RECLS_PLATFORM_ API_WIN32
// recls_time_t is FILETIME

// you have to convert using FileTimeToSyste mTime
FILETIME t1 = entry.GetCreati onTime();
FILETIME t2 = entry.GetModifi cationTime();
FILETIME t3 = entry.GetLastAc cessTime();
FILETIME t4 = entry.GetLastSt atusChangeTime( );
#else
// recls_time_t is time_t

// you have to convert using gmtime
time_t t1 = entry.GetCreati onTime();
time_t t2 = entry.GetModifi cationTime();
time_t t3 = entry.GetLastAc cessTime();
time_t t4 = entry.GetLastSt atusChangeTime( );
#endif

If you have a cross-platform time class you can just convert to your
time class and not worry about it. Date/time is such a drag. recls
seems to just ignore the problema dn leave it to the user.

If you can get round the time/size hasslles, it's otherwise good. I use
it for recusrive searches whenever I need it.

Thanks a lot u guys for ur kind help. I m really glad that u came up
with nice ideas n solutions. Thanks again;
Regards;
Saleem

Dec 23 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2184
by: Astra | last post by:
Hi All Is there an ASP way of extracting the height and width of a swf file so that I can specify these dims when adding the whole OBJECT code to the web page? Thanks Robbie
2
3816
by: Chris Millar | last post by:
Can anyone help me on converting this vb asp page to C#, thanks in advance. chris. <!DOCTYPE HTML PUBLIC "-//W3C//Dtd HTML 4.0 transitional//EN"> <% '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''
1
1012
by: bill | last post by:
I have been asked to design a file server application. Here are the particulars: The data that is to be served is on a 80Gbyte USB drive connected to a USB 2.0 port. That disk needs to be used by 2 applications. One archives the disk data to another drive, the other does timed seeks extracting 2Mbyte chunks. Now the cruxt of the juxtaposition: The USB drive is only low-level
3
4871
by: Kris van der Mast | last post by:
Hi, I've created a little site for my sports club. In the root folder there are pages that are viewable by every anonymous user but at a certain subfolder my administration pages should be protected by forms authentication. When I create forms authentication at root level it works but when I move my code up to the subfolder I get this error: Server Error in '/TestProjects/FormsAuthenticationTestingArea' Application.
3
5060
by: Mae | last post by:
Dear All, I have a problem here, I'm using C# Webform calling a webservices. The webservices return me a XMLnode, using this XMLnode I want to convert it to dataset so I can bind to the datagrid, by extracting the <CustomerData></CustomerData> block from the xmlnode. Below is the sample of xmlnode return from webservices. <?xml version="1.0" encoding="utf-8"?>
2
5047
by: John Regan | last post by:
Hello All I am trying to find the owner of a file or folder on our network (Windows 2000 Server) using VB.Net and/or API. so I can search for Folders that don't follow our company's specified folder structure and naming conventions and then send a Net send message to those users telling them to rectify. The information I want to get is when you select the file/folder and then: Properties -> Security Tab -> Advanced Button -> Owner Tab ->...
0
2426
by: georges the man | last post by:
The purpose: • Sorting and Searching • Numerical Analysis Design Specification You are to write a program called “StockAnalyser”. Your program will read a text file that contains historical price of a stock. The program will allow users to query the stock price of a particular date and output its statistics (mean price, median price and standard deviation) for any specified period. Your program must be menu driven and works as follows.
0
2225
by: Jack Wu | last post by:
Hi I've spent a good majority of my day trying to figure out how to have PIL 1.1.5 working on my OSX 10.3.9_PPC machine. I'm still stuck and I have not gotten anywhere. Could somebody please help me... I've scoured all the documentation, google, and mailing lists to no avail. I believe the problem may lay in a jpeglib problem with OSX 10.3.9, or a python paths problem.
0
1481
by: sgsiaokia | last post by:
I need help in extracting data from another source file using VBA. I have problems copying the extracted data and format into the required data format. And also, how do i delete the row that is not required in the output file, in the below example: The row, D0, is not needed. An Example Data Format From the SOURCE file: W1 W2 W3 W4 Oct05 AverageYield 95% 96% 92% 91% 94% D0 0.1 ...
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10113
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8995
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4074
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2896
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.