Sponsored Content
Full Discussion: Q with stat()
Top Forums Programming Q with stat() Post 302235323 by JamesGoh on Thursday 11th of September 2008 06:28:49 PM
Old 09-11-2008
Q with stat()

From reading various articles on the net, I know stat() is used on files to get things like permissions, sizes etc... As a folder is a special type of file in Unix, I assumed that stat() could work on it as well as any general file.

However, from running my program, perror() reported that the folder does not exist, so Im curious to know what Ive done wrong

Code:
struct dirent *list;
DIR *d_entry;
struct stat buff;

/*Open directory & access 
elements within it*/

if( stat(list->d_name,&buff) == -1)
{
   perror("stat()");
}

else
{
....
}

thanks in advance
 

10 More Discussions You Might Find Interesting

1. Programming

stat() fails!!! what can i do?

Hi all, I can not understand why my stat() function fails all the time when function tries to go recursevly. Someone suggested that it might be poiter problem. Please, look up my code at: www.donnelly.cc.ks.us/readdir_test.c. How can i solve this problem? Any suggestion are welcome! Thank you... (3 Replies)
Discussion started by: solvman
3 Replies

2. UNIX for Dummies Questions & Answers

Cannot stat?

Hi! I ran into a problem with a job I'm running. All it is doing is a "touch" on a filename. However, when I ran the job, it error'd out and got the message 'cannot stat'. When I restarted the job (making no changes) it worked just fine. Anyone know what this means? (1 Reply)
Discussion started by: lgardner
1 Replies

3. UNIX for Advanced & Expert Users

stat

the output of stat command is Size: 238 Blocks: 8 IO Block: 4096 regular file Device: 80ah/2058d Inode: 736783 Links: 1 Access: (0664/-rw-rw-r--) Uid: ( 500/ gajju) Gid: ( 500/ gajju) Access: 2008-09-08 20:00:15.000000000 +0530 Modify: 2008-09-08... (6 Replies)
Discussion started by: gajju
6 Replies

4. Solaris

stat: Available on Solaris?

JoeyG's note in the following thread got me thinking about using stat more often in file operations. I've only ever used it within perl - didn't even realize there was a commandline version of it.... (3 Replies)
Discussion started by: Smiling Dragon
3 Replies

5. Shell Programming and Scripting

stat command with ls -l

If i do ls -l i get the result rwx-rw-r ...... ............... file. How can i get the result in octal format. All other output will be the same as ls -l shows. The rwx-rw-r would be like 755 etc. (7 Replies)
Discussion started by: cola
7 Replies

6. Shell Programming and Scripting

using File::stat

Hello everyone, I need some help on a perl script. The script is to open a dir and print out the date of last modification on all files. I'm been trying this code but it doesn't work. use File::stat; open (D,"$ARGV") or die "Can't open\n"; while (defined ($file = readdir D)) { next... (3 Replies)
Discussion started by: new bie
3 Replies

7. UNIX for Dummies Questions & Answers

stat output

hi guys i got confused about stat output stat manual says File : Size in Bytes Blocks : Number of blocks used IO Block : Size in bytes of every block. when i use stat command for passwd file it says ~#stat /etc/passwd File: `/etc/passwd' Size: 999 Blocks: 8 IO... (4 Replies)
Discussion started by: mhs
4 Replies

8. UNIX for Dummies Questions & Answers

Stat command

i know this command does not exist in solaris. however, i read somewhere on this forum that basically everything the stat command provides in other oses can be obtained in solaris using the ls command. i've searched the forum for a while now and i cant find the thread. does anyone know about... (1 Reply)
Discussion started by: SkySmart
1 Replies

9. Shell Programming and Scripting

Stat value changes

Die to what all operations, the "Modify" and "Change" values of stat output changes for a file. I found, during editing a file, Change and Modify alters. When chmod'ing Change alters, while Modify doesnot alters. Is there more situations where these changes? (1 Reply)
Discussion started by: anil510
1 Replies

10. UNIX for Dummies Questions & Answers

Help with stat command

Hi Experts, I am here with very simple request: #!bin/bash a=`stat -c %y log1.csv` echo $a and this stat command returning value as 2013-08-11 05:42:10.000000000 -0400: But I want to see in mm/dd/yyyy format? any help is highly appreciated thank you ---------- Post... (9 Replies)
Discussion started by: parpaa
9 Replies
Tcl_Access(3)						      Tcl Library Procedures						     Tcl_Access(3)

__________________________________________________________________________________________________________________________________________________

NAME
Tcl_Access, Tcl_Stat - check file permissions and other attributes SYNOPSIS
#include <tcl.h> int Tcl_Access(path, mode) int Tcl_Stat(path, statPtr) ARGUMENTS
char *path (in) Native name of the file to check the attributes of. int mode (in) Mask consisting of one or more of R_OK, W_OK, X_OK and F_OK. R_OK, W_OK and X_OK request checking whether the file exists and has read, write and execute permissions, respectively. F_OK just requests checking for the existence of the file. struct stat *statPtr (out) The structure that contains the result. _________________________________________________________________ DESCRIPTION
As of Tcl 8.4, the object-based APIs Tcl_FSAccess and Tcl_FSStat should be used in preference to Tcl_Access and Tcl_Stat, wherever possi- ble. There are two reasons for calling Tcl_Access and Tcl_Stat rather than calling system level functions access and stat directly. First, the Windows implementation of both functions fixes some bugs in the system level calls. Second, both Tcl_Access and Tcl_Stat (as well as Tcl_OpenFileChannelProc) hook into a linked list of functions. This allows the possibility to reroute file access to alternative media or access methods. Tcl_Access checks whether the process would be allowed to read, write or test for existence of the file (or other file system object) whose name is pathname. If pathname is a symbolic link on Unix, then permissions of the file referred by this symbolic link are tested. On success (all requested permissions granted), zero is returned. On error (at least one bit in mode asked for a permission that is denied, or some other error occurred), -1 is returned. Tcl_Stat fills the stat structure statPtr with information about the specified file. You do not need any access rights to the file to get this information but you need search rights to all directories named in the path leading to the file. The stat structure includes info regarding device, inode (always 0 on Windows), privilege mode, nlink (always 1 on Windows), user id (always 0 on Windows), group id (always 0 on Windows), rdev (same as device on Windows), size, last access time, last modification time, and creation time. If path exists, Tcl_Stat returns 0 and the stat structure is filled with data. Otherwise, -1 is returned, and no stat info is given. KEYWORDS
stat, access Tcl 8.1 Tcl_Access(3)
All times are GMT -4. The time now is 07:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy