readdir

How to use S_ISREG() and S_ISDIR() POSIX Macros?

断了今生、忘了曾经 提交于 2019-11-27 08:43:34
This is a C program I wrote to recursively navigate and output directories and regular files. It compiles and runs fine on my Linux machine. But on Solaris, the dit->d_type == 8 check and the other similar ones don't work because there is no d_type field. An answer I've read to this problem is to use the S_ISREG() and S_ISDIR() macros, but they don't work at all the way I have them in my code currently. I commented out the lines that work on my Linux machine. #include <sys/types.h> #include <sys/stat.h> #include <stdlib.h> #include <dirent.h> #include <stdio.h> #include <unistd.h> #include

What reasons are there to prefer glob over readdir (or vice-versa) in Perl?

▼魔方 西西 提交于 2019-11-27 06:52:01
This question is a spin-off from this one . Some history: when I first learned Perl, I pretty much always used glob rather than opendir + readdir because I found it easier. Then later various posts and readings suggested that glob was bad, and so now I pretty much always use readdir . After thinking over this recent question I realized that my reasons for one or the other choice may be bunk. So, I'm going to lay out some pros and cons, and I'm hoping that more experienced Perl folks can chime in and clarify. The question in a nutshell is are there compelling reasons to prefer glob to readdir

Does readdir() guarantee an order?

怎甘沉沦 提交于 2019-11-27 04:20:33
I'm getting a list of files on a linux-like system using opendir/readdir. It appears that the directory entries are returned in alphabetical order of file name. However, I don't see anything in the man pages about this order being guaranteed. Can anyone tell me whether or not readdir guarrantees an order? The readdir method doesn't guarantee any ordering. If you want to ensure they are sorted alphabetically you'll need to do so yourself. Note: I searched for a bit for definitive documentation saying this is the case. The closest I came is the following link http://utcc.utoronto.ca/~cks/space

Checking if a dir. entry returned by readdir is a directory, link or file. dent->d_type isn't showing the type

醉酒当歌 提交于 2019-11-27 02:10:19
I am making a program which is run in a Linux shell, and accepts an argument (a directory), and displays all the files in the directory, along with their type. Output should be like this: << ./Program testDirectory Dir directory1 lnk linkprogram.c reg file.txt If no argument is made, it uses the current directory. Here is my code: #include <stdio.h> #include <dirent.h> #include <sys/stat.h> int main(int argc, char *argv[]) { struct stat info; DIR *dirp; struct dirent* dent; //If no args if (argc == 1) { argv[1] = "."; dirp = opendir(argv[1]); // specify directory here: "." is the "current

Microsoft Visual Studio: opendir() and readdir(), how?

血红的双手。 提交于 2019-11-26 17:57:22
I've used this kind of code in my Dev-cpp before: if((dh = opendir(folder)) !== false){ while((file = readdir(dh)) !== false){ // do my stuff } closedir(dh); } But now i am using MSVC++ and i dont know how to add those files there, i tried to copy dirent.h/dir.h/errno.h in there, but it gives another error relating to another included files inside those files ..., and by looking in the files i see mingw stuff there so its compiler related? idk what compiler MSVC++ uses, but is it possible to copypaste those files in MSVC++ and get it working? I tried to look up some code from MSDN but it was

Why does stat fail using a name from readdir?

自作多情 提交于 2019-11-26 13:54:06
I wrote a program that print the directory name or file name. It's easy but I got something trouble. It couldn't distinguish directory and file type. I know and I used stat.st_mode to finish it. But something is wrong: When I use gdb to check the st_mode value, I found it was 0, except "." and "..", so here is the question: why st_mode is 0? and that is my code: #include <stdio.h> #include <stdlib.h> #include <dirent.h> #include <sys/stat.h> int main(void) { DIR *pDir = opendir("MyDirectory"); struct dirent *pDirent; struct stat vStat; if (pDir == NULL) { printf("Can't open the directory \

What reasons are there to prefer glob over readdir (or vice-versa) in Perl?

倖福魔咒の 提交于 2019-11-26 12:57:01
问题 This question is a spin-off from this one. Some history: when I first learned Perl, I pretty much always used glob rather than opendir + readdir because I found it easier. Then later various posts and readings suggested that glob was bad, and so now I pretty much always use readdir . After thinking over this recent question I realized that my reasons for one or the other choice may be bunk. So, I\'m going to lay out some pros and cons, and I\'m hoping that more experienced Perl folks can

php readdir problem with japanese language file name

允我心安 提交于 2019-11-26 12:33:24
问题 I have the following code <?php if ($handle = opendir(\'C:/xampp/htdocs/movies\')) { while (false !== ($file = readdir($handle))) { if ($file != \".\" && $file != \"..\") { echo $file.\"<br />\\n\"; } } closedir($handle); } ?> When it does have mb language such as japanese, it doesn\'t display properly instead it display like kyuukyoku Choujin R ?????~? rather then kyuukyoku Choujin R 究極超人あ~る Anyway to make it display the correct name or make it still download-able by others? Thanks for

Checking if a dir. entry returned by readdir is a directory, link or file. dent->d_type isn&#39;t showing the type

折月煮酒 提交于 2019-11-26 09:54:56
问题 I am making a program which is run in a Linux shell, and accepts an argument (a directory), and displays all the files in the directory, along with their type. Output should be like this: << ./Program testDirectory Dir directory1 lnk linkprogram.c reg file.txt If no argument is made, it uses the current directory. Here is my code: #include <stdio.h> #include <dirent.h> #include <sys/stat.h> int main(int argc, char *argv[]) { struct stat info; DIR *dirp; struct dirent* dent; //If no args if

Why does stat fail using a name from readdir?

旧巷老猫 提交于 2019-11-26 03:45:45
问题 I wrote a program that print the directory name or file name. It\'s easy but I got something trouble. It couldn\'t distinguish directory and file type. I know and I used stat.st_mode to finish it. But something is wrong: When I use gdb to check the st_mode value, I found it was 0, except \".\" and \"..\", so here is the question: why st_mode is 0? and that is my code: #include <stdio.h> #include <stdlib.h> #include <dirent.h> #include <sys/stat.h> int main(void) { DIR *pDir = opendir(\