Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
2 votes
0 answers
54 views

Good way to understand if file has been just created rather than modified in Linux

I need a way to learn if a file has been just created (rather than e.g. modified). I do it like this: const bool isCreated = ((f.atime.tv_sec == f.mtime.tv_sec) && ...
JenyaKh's user avatar
  • 2,458
0 votes
1 answer
153 views

fread is reading the last part of my text file twice

I have a text file I want to read into an std::vector. It's okay if the vector is a little too big, but it seems to be doing a very weird thing: It's copying the entire file, then copying a portion ...
Anne Quinn's user avatar
1 vote
0 answers
45 views

When can st_ino change for a direcory?

I am trying to work with StructStat class in Android. As per android documentation at here st_ino represents File Serial Number of object st_blocks represents number of blocks allocated to this ...
Kushal's user avatar
  • 8,488
0 votes
2 answers
192 views

How's stat function used in Perl?

Can anyone help me to understand the meaning of below line? #!/usr/bin/perl use File::stat; ... sub rootdev { return (stat readlink)[0] == (stat "/")[0]; } my @vols = shuffle map {/.*\/([...
Hardguy's user avatar
  • 43
2 votes
2 answers
1k views

Stat function not working when passing file names of different directories [duplicate]

I am trying to implement the ls command and am getting stuck in the -i option using the stat() function to list inode numbers. The format is ./myls [options] [list of files] If I run ./myls -i . I ...
callum arul's user avatar
1 vote
1 answer
1k views

How to convert string permission to mode_t type

I am writing a program which changes file permissions. The permissions will be passed through a command line argument as a char * and then converted to mode_t type and given to chmod(). How could I ...
programme3219873's user avatar
2 votes
1 answer
692 views

how to change file timestamp including nanoseconds

I am making a program to copy files from a source to a destination directory and would like to change the destination file timestamps so they match the source file timestamps. So far I have discovered ...
programme3219873's user avatar
0 votes
0 answers
186 views

loading a files metadata into another file using stat()

I am writing a program to copy a file from a source directory x to a destination directory y. However i used stat() to get file metadata from the source file. Is there any way i could somehow load the ...
programme3219873's user avatar
0 votes
2 answers
160 views

Directory inside directory is seen as file

I am trying to open a directory and read the files and folders and add '/' at the end of if it is a folder. This is my current code. #include <dirent.h> #include <sys/stat.h> #include <...
rasput1n's user avatar
0 votes
1 answer
199 views

How to get correct file size only on the completion of a detected file change, not at the beginning?

I'm using libuv's uv_fs_event_t to monitor file changes. And once a change is detected, I open the file in the callback uv_fs_event_cb. However, my program requires to also get the full file size when ...
Superziyi's user avatar
  • 619
0 votes
1 answer
297 views

cp: cannot stat 'AmritaAura_local/amrita_aura/aura': No such file or directory

When I try to copy the files in virtual environment I get the above error.The command is cp -r AmritaAura_local/amrita_aura/aura AmritaAura_local/local_setup/venv/lib/python2.7/site-packages. Where ...
Chandrashekhar's user avatar
4 votes
2 answers
5k views

Check if a file is 20 hours old in ansible

I'm able to get the timestamp of a file using Ansible stat module. - stat: path: "/var/test.log" register: filedets - debug: msg: "{{ filedets.stat.mtime }}" The above ...
Ashar's user avatar
  • 3,161
2 votes
2 answers
3k views

how to check if any of the files in a directory changed

Given a directory, I'd like to know whether the files in the directory have been modified or not. (Boolean) i.e. if the directory's state has changed from before. I don't want to run a file watcher ...
Phani Rithvij's user avatar
0 votes
0 answers
529 views

Does FTP's STAT [file] command (LIST [file]) guarantee proper status of file currently locked?

I searched the Internet about the problem with file being uploaded on the FTP, no locking mechanism what results in not knowing if file that FTP client want to get is being uploaded. Main articles ...
Ferdynand Kiepski's user avatar
0 votes
2 answers
310 views

How to count file in function of their age in Python?

I'm trying to count how many file are very young, young, old and very old in a directory passed by command line. I have some struggle counting the number of file in the directory and then to change ...
J.erome's user avatar
  • 768
0 votes
1 answer
161 views

Where file status info actually store?

Where the file status info actually store when we using stat() in to get? I'am learning Unix Programing, But i am confused when i using stat() function to get file status. There are no any ...
l33klin's user avatar
1 vote
0 answers
162 views

How to count the files in a directory using C

The canonical way of determining a file's type is to use the commented out code in this snippet: // Return the number of files in dirName. Ignore directories and links. #include <sys/types.h> #...
Boffin's user avatar
  • 161
2 votes
1 answer
2k views

Python3: Recursively compare two directories based on file contents

I have two directories containing a bunch of files and subfolders. I would like to check if the file contents are the same in both directories (ignoring the file name). The subfolder structure should ...
langlauf.io's user avatar
  • 3,161
3 votes
1 answer
3k views

What is the meaning of each field with the output of `stat` on OSX?

$ stat Cargo.toml 16777220 9094681422 -rw-r--r-- 1 tonytonyjan staff 0 109 "Jan 19 10:05:13 2019" "Dec 31 17:52:29 2018" "Dec 31 17:52:29 2018" "Dec 14 16:32:26 2018" 4096 8 0 Cargo.toml man stat ...
Weihang Jian's user avatar
  • 8,636
0 votes
0 answers
57 views

file opened before function call (optimization issue)?

I am trying to understand this better... I have a function in main that is called only when certain conditions are true - inside that function is... struct stat attr_buff; if (stat( filename, &...
Krpan's user avatar
  • 9
1 vote
1 answer
195 views

Is filesize/stat consistent across all filesystems?

I am considering writing software which uses the filesize as pretest to test whether two files are equivalent. There is no need to apply sophisticated file content comparisons if a simple file size ...
meisterluk's user avatar
1 vote
1 answer
206 views

Check for file existance and read permissions

I am trying to check if my file specified by file_path exists and is readable. This is my code: if (stat(file_path,&fileStat) > 0 && (fileStat.st_mode & S_IRUSR)) { puts("...
Darren Col's user avatar
-1 votes
1 answer
168 views

obtain owner name and group from stat function c++

Good day every one. I use function stat on windows to get information from file, but how i can get name from st_uid and st_gid (it's a short). I use visual stydio 2015
Вячеслав Кириллов's user avatar
-3 votes
1 answer
1k views

C - stat struct not working properly [duplicate]

I am trying to printf some characteristics of the files inside a directory (only the ones that start with lowercase). However, when I execute the following code, some of them work and some don't. It ...
Eduardo Ramos's user avatar
1 vote
3 answers
640 views

How to increment a value without any for loop but based on number of times the file is run in PHP

I have a script which, when it runs, creates a new file in some directory. While creating a new file it checks if the file exists: If it exists it should append 1 to the file name If another file has ...
Mann's user avatar
  • 606
0 votes
0 answers
503 views

stat not recognizing directoies

Hello I´m working on a du implementation that only calculates the size of regular files, so far I got this : childAnswer* list(char* path){ DIR *directory; struct dirent *filei; struct ...
Stieg's user avatar
  • 138
1 vote
1 answer
44 views

Extract to file duplicate information

I want to create the file with particular name. If it already exists then I want to create another file with the name appended by some number. For example, I want to create the file log.txt but it is ...
redchicken's user avatar
1 vote
2 answers
170 views

How to count only the number of directories from a path

I am trying to count only the directories from a path, but it doesn't work. So, i don't want to number both files and directories, i want only the directories. Could you help me, please? The code: ...
Sebi95's user avatar
  • 161
4 votes
2 answers
1k views

How to get a files last changed time (Unix + Java)

In Unix there is a difference between last changed time and last modifies time. For example when using stat I can get: Access: 2016-01-18 10:50:01.624303144 +0100 Modify: 2016-01-12 13:34:18....
Arenlind's user avatar
1 vote
1 answer
3k views

Perl: Get the user name and group name from stat commad

Here is the code snippet I am using and I am unable to get the user name and group name for the required file. #!/usr/bin/perl use strict; use Data::Dumper; use File::stat; $somedir = '/var/vob/...
Shantesh's user avatar
  • 1,590
2 votes
3 answers
2k views

How not to open a file twice in linux?

I have a linked list with an fd and a string I used to open this file in each entry. I want to open and add files to this list only if this file is not already opened, because I open and parse this ...
sivizius's user avatar
  • 460
-2 votes
1 answer
187 views

Linux block size issue

When I run stat for a file test I got the following output. > [ec2-user@ip-172-31-55-186 ~]$ stat test > File: ‘test’ Size: 538 > Blocks: 8 IO Block: 4096 regular file ...
Balasekhar Nelli's user avatar
13 votes
1 answer
8k views

On Linux, is access() faster than stat()?

I would have assumed that access() was just a wrapper around stat(), but I've been googling around and have found some anecdotes about replacing stat calls with 'cheaper' access calls. Assuming you ...
Joseph Garvin's user avatar
0 votes
1 answer
1k views

C struct stat info not updating in a loop, giving ridiculous modification date

For one part of a code, I need to save both the name and the stats (user ID, group ID, modification time, permissions, etc.) of every file in a given directory into an array of self-defined structs. ...
jiccan's user avatar
  • 89
0 votes
1 answer
560 views

stat function returns empty struct [duplicate]

studentsDir = opendir(lineValues); while ((entry = readdir(studentsDir)) != NULL) { stat(path, &dirData); if (S_ISDIR(dirData.st_mode) && (entry->d_name[0] != '.') &...
user2740785's user avatar
0 votes
1 answer
636 views

Finding the size of a file from stdin gives incorrect number

I am reading a file name off the standard input and the function returns something that is completely wrong. The code below returns 4294967296 rather than what should be 7. I am running the file like ...
FullCombatBeard's user avatar
5 votes
1 answer
2k views

Get a sorted list of folders based on modification date

I am trying to figure out how to apply a Python function to the oldest 50% of the sub-folders inside my parent directory. For instance, if I have 12 folders inside a directory called foo, I'd ...
stratis's user avatar
  • 8,022
10 votes
5 answers
14k views

What are the advantages of using fstat() vs stat()?

If I have an open file with a known file descriptor, what are the advantages of using fstat(), versus stat()? Why isn't there only one function? int fstat(int fildes, struct stat *buf) int stat(...
Rasteril's user avatar
  • 615
3 votes
1 answer
3k views

How to get file info in Python3 using os.listdir?

I simplified the problem. Now I have only this code: files = os.listdir(dir_path) print(files) for f in files: info = os.stat(f) print(info.st_mtime) Which gives me this error: OSError: [...
forvas's user avatar
  • 10.1k
0 votes
1 answer
158 views

How to hide . and .. folders in C?

I'm trying to list all folders and all files of a folder with the language C. This is the following code: #include <errno.h> #include <stdio.h> #include <dirent.h> #include <sys/...
Lord Rixuel's user avatar
  • 1,233
0 votes
1 answer
516 views

When testing a file for readability using stat() do I need to test S_IRUSR, S_IRGRP & S_IROTH?

I'm writing a program using stat to look at file attributes. When testing to see if a file is readable, do I need to test all three modes S_IRUSR, S_IRGRP & S_IROTH or is there a single test for ...
CyberSkull's user avatar
1 vote
1 answer
2k views

List files and their info using stat

I am programming an ftp server using c++ and I need to be able to get all info about files in form of : sent: drwxr-xr-x 1000 ubuntu ubuntu 4096 May 16 11:44 Package-Debug.bash so I can send it to ...
user2274361's user avatar
-1 votes
1 answer
4k views

Python: Windows System File

In python, how can I identify a file that is a "window system file". From the command line I can do this with the following command: ATTRIB "c:\file_path_name.txt" If the return has the "S" ...
stev's user avatar
  • 1
-3 votes
3 answers
6k views

how to determine if two file are identical in c using system call

i need to see if 2 files are identical so i used struct stat fdin = open(argv[0],O_RDONLY); statos= fstat(fdin, &stat); close(fdin); fdin = open(argv[1],O_RDONLY); statos1= ...
Moshe Ovadia's user avatar
20 votes
4 answers
77k views

Implementing the ls -al command in C

As a part of an assignment from one of my classes, I have to write a program in C to duplicate the results of the ls -al command. I have read up on the necessary materials but I am still not getting ...
ankur3000's user avatar
  • 203
2 votes
1 answer
1k views

Read all bytes from a file in c

I'm trying to read bytes from a file, but the size is corrupt. When debugging I can see the value of st.st_size, but I can't read the value of size. int main(void) { FILE* oud; struct stat st;...
user avatar
-2 votes
1 answer
2k views

c comparing file sizes using fstat issue

My code comparing 2 file sizes seems to behave as if keyfile > sourcefile. Is there something missing from the code below and what can I change? The two files I'm using for testing are 3kb keyfile and ...
youjustreadthis's user avatar
0 votes
2 answers
6k views

Modified time using os.stat in Python gets lower when copying files

The issue I am running into is part of using os.stat on a path (Take C:\myfile1.txt for example). When I run os.stat on this file and take the 9th element in the resulting list I get the modified time ...
Brad Conyers's user avatar
  • 1,251
1 vote
1 answer
433 views

file accessed time in linux using python

This question is a continuation of my question in another thread.Since the point of this question is slightly different,I thought I'd post it as a new question. I experimented getting accessed time ...
damon's user avatar
  • 8,417
2 votes
3 answers
1k views

Do I need to fflush or close a file before calling stat on it?

After opening a file for writing: FILE *file = fopen("./file", "w"); Can I assume the file was created immediately? Is it safe to call: stat( "./file", info); Or should I better: fflush(file); ...
Ynv's user avatar
  • 1,964