473,659 Members | 3,117 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

alternative to fstat ?

I have thousands of files whose exitence needs to be checked.
I think fstat is too costly for this.
Is there any better way for the same ?
Dec 11 '07 #1
11 5141
"solarisss" <sa************ **@gmail.comsch rieb im Newsbeitrag
news:d6******** *************** ***********@s19 g2000prg.google groups.com...
>I have thousands of files whose exitence needs to be checked.
I think fstat is too costly for this.
Is there any better way for the same ?
OT here, but in POSIX you'd have stat() (which would save you the fopen())
and access() (which should be much cheaper as it doesn't have to fill the
entire struct stat).

Bye, Jojo
Dec 11 '07 #2
In article <fj**********@o nline.de>,
Joachim Schmitz <jo**@schmitz-digital.dewrote :
>OT here, but in POSIX you'd have stat() (which would save you the fopen())
and access() (which should be much cheaper as it doesn't have to fill the
entire struct stat).
I doubt access() would be significantly cheaper since it still has
to do a system call and get the inode of the file.

-- Richard
--
:wq
Dec 11 '07 #3
"Richard Tobin" <ri*****@cogsci .ed.ac.ukschrie b im Newsbeitrag
news:fj******** ***@pc-news.cogsci.ed. ac.uk...
In article <fj**********@o nline.de>,
Joachim Schmitz <jo**@schmitz-digital.dewrote :
>>OT here, but in POSIX you'd have stat() (which would save you the fopen())
and access() (which should be much cheaper as it doesn't have to fill the
entire struct stat).

I doubt access() would be significantly cheaper since it still has
to do a system call and get the inode of the file.
It is significantly cheaper on a system I frequently work with.

Bye, Jojo
Dec 11 '07 #4
solarisss <sa************ **@gmail.comwro te:
# I have thousands of files whose exitence needs to be checked.
# I think fstat is too costly for this.
# Is there any better way for the same ?

stat information is not generally stored as part of the directory;
getting inode information generally generally requires a random
disc access. Some file systems might allow store inodes to improve
reading them, but that would be implementation dependent.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
There are subtler ways of badgering a witness.
Dec 11 '07 #5
solarisss schrieb:
I have thousands of files whose exitence needs to be checked.
I think fstat is too costly for this.
Is there any better way for the same ?
if the files are located in few common directories, fstatat might be an
option on Solaris. Don't know about other systems...

- Thomas
Dec 11 '07 #6
Joachim Schmitz wrote:
>
"solarisss" <sa************ **@gmail.comsch rieb im Newsbeitrag
news:d6******** *************** ***********@s19 g2000prg.google groups.com...
I have thousands of files whose exitence needs to be checked.
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^
I think fstat is too costly for this.
Is there any better way for the same ?
OT here, but in POSIX you'd have stat() (which would save you the fopen())
and access() (which should be much cheaper as it doesn't have to fill the
entire struct stat).
Well, if you have a file handle to pass to fstat(), I think we can
pretty much agree that the file exists. (Even if POSIX is OT here.)

:-)

And, if I recall, a discussion in the past noted that a failed access()
call doesn't necessarily mean the file doesn't exist. (For example,
you may simply not have permission to check for the existence.) Also,
there was a discussion about some sort of "cryptograp hic filesystem"(?)
in which the existence of a file cannot be determined.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer .h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th***** ********@gmail. com>

Dec 11 '07 #7
"Kenneth Brody" <ke******@spamc op.netschrieb im Newsbeitrag
news:47******** *******@spamcop .net...
Joachim Schmitz wrote:
>>
"solarisss" <sa************ **@gmail.comsch rieb im Newsbeitrag
news:d6******* *************** ************@s1 9g2000prg.googl egroups.com...
>I have thousands of files whose exitence needs to be checked.
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^
I think fstat is too costly for this.
Is there any better way for the same ?
OT here, but in POSIX you'd have stat() (which would save you the
fopen())
and access() (which should be much cheaper as it doesn't have to fill the
entire struct stat).

Well, if you have a file handle to pass to fstat(), I think we can
pretty much agree that the file exists. (Even if POSIX is OT here.)

:-)
Oops...
And, if I recall, a discussion in the past noted that a failed access()
call doesn't necessarily mean the file doesn't exist. (For example,
you may simply not have permission to check for the existence.) Also,
Very true, so you would have to check errno in case access() returns a -1.

printf("%s does%s exist\n", filename, ((access(filena me) == -1) && (errno==
ENOFILE))? "n't":"");

The same is true for stat BTW(). And for fstat() resp. the open() it needs.

Bye, Jojo
Dec 11 '07 #8
Joachim Schmitz wrote:
>
"Kenneth Brody" <ke******@spamc op.netschrieb im Newsbeitrag
news:47******** *******@spamcop .net...
Joachim Schmitz wrote:
[... use fstat() to check for file existence ...]
Well, if you have a file handle to pass to fstat(), I think we can
pretty much agree that the file exists. (Even if POSIX is OT here.)

:-)
Oops...
And, if I recall, a discussion in the past noted that a failed access()
call doesn't necessarily mean the file doesn't exist. (For example,
you may simply not have permission to check for the existence.) Also,
Very true, so you would have to check errno in case access() returns a -1.

printf("%s does%s exist\n", filename, ((access(filena me) == -1) && (errno==
ENOFILE))? "n't":"");

The same is true for stat BTW(). And for fstat() resp. the open() it needs.
(I'm not sure why we're discussing POSIX here, but...)

What if the file doesn't exist in a directory to which you do not
have the proper permissions? I believe the error will be EPERM
(or, at least, not ENOFILE), and you will display "does exist".

The point is, an error other than ENOFILE does not imply that the
file does exist. I believe the same holds true for stat() et al.
The only thing you can reliably check for is whether you can open
the file, by seeing what fopen() returns. (Yes, you can use
something like access() to see if you have permission to a file
_at_the_time_yo u_call_access() _, but you have race conditions to
take into account.)

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer .h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th***** ********@gmail. com>

Dec 11 '07 #9
solarisss <sa************ **@gmail.comwri tes:
I have thousands of files whose exitence needs to be checked.
I think fstat is too costly for this.
Is there any better way for the same ?
Since fstat() is defined by POSIX, I suggest that comp.unix.progr ammer
would provide better answers to your question.

--
Keith Thompson (The_Other_Keit h) <ks***@mib.or g>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Dec 11 '07 #10

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

Similar topics

99
4616
by: Paul McGuire | last post by:
There are a number of messages on the python-dev mail list that indicate that Guido is looking for some concensus to come from this list as to what *one* alternative syntax for decorators we would like him to consider in place of the @ syntax that is currently in 2.4a2. I think special thanks are due to: - Anthony Baxter for his continuing efforts in this regard - Steven Bethard for some of the clearest thinking and writing on this topic...
28
2378
by: Paul McGuire | last post by:
Well, after 3 days of open polling, the number of additional votes have dropped off pretty dramatically. Here are the results so far: Total voters: 55 (with 3 votes each) Votes for each choice or group of choices: Any J 81 J2 78 Any C 40 C1 29 Any D 9
4
7618
by: Klaus Füller | last post by:
I would like to use the unix,et.al-fstat() system-call on some sort of stream which is already open and connected to a disk file. An example: I have an open stream and want to know the numerical owner-id of the file associated with the stream. I can write the code myself if someone tells me how to get the filedescriptor that must be buried as a member attribute somewhere in the stream-classes. Eventually all io must pass through such...
1
13291
by: prasaddevivara | last post by:
I am using the outerHTML property to modify the HTML of existin elements in a web page in Internet Explorer. But same outerHTM property is not working in firefox browser, Anybody can tell me a alternative for outerHTML property in firefox. I am using th following function to display an image and alternate text behind al images of a weg page in Internet Explorer. Anybody can give solutio for same in firefox browser. function...
2
4884
by: Martijn | last post by:
Hi, I have an open file handle from which I would like to retrieve the file descriptor for use with fstat. Is this possible or should I redesign my algorithm a bit (I have the feeling I am overlooking something trivial here)? Thanks, Martijn
1
2366
by: Mark Fink | last post by:
Hi there, unfortunately I am new to Jython and my "Jython Essentials" book is still in the mail. I looked into the Jython API Doc but could not find the information. I am porting a Python library to Jython and some parts are missing. My question basically is where do I find information on what to use instead. E.g. I could not find information on the os module. I do not find the sys module docu either. The concrete problem is I have...
3
2602
by: Will McGugan | last post by:
Hi, Is there a naming convention regarding alternative constructors? ie static methods where __new__ is called explicity. I use lower_case for methods in general, but thought maybe CamelCase would be better for alternative contstructors to distinguish them from methods... So which is better? c = Color.FromHtml(r, g, b)
0
2783
by: sachintandon | last post by:
Hello all, Thanks in advance for your help I have a problem in sending emails, my requirement is to send multipart alternative emails with attachments, I'm able to send text with attachments or HTML mails with attachments, but some mail clients are not able to display the html mails that is why I need to send multipart alternative emails, when I used multipart/alternative then I'm not able to send attachments and if I use the multipart/mixed...
1
6313
by: Lars B | last post by:
Hey guys, I have written a C++ program that passes data from a file to an FPGA board and back again using software and DMA buffers. In my program I need to compare the size of a given file against a software buffer of size 3MB. This is needed so as to see which function to use to read from the file. As the files used range from very large (>30GB) to very small (<3MB), I have enabled large file support and I obtain the file size by using the...
0
8428
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
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8528
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
8627
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
7356
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
5649
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();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2752
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
1737
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.