opendir

opendir() in C Programming

家住魔仙堡 提交于 2021-02-19 16:32:13
问题 I'm a beginner and I am making a code about getting the directory of a file, but I have something that I don't understand. What's the meaning of "./" in DS = opendir ("./"); I have searched a lot of sites about C programming, but nothing gave me a good explanation. I have to present my code soon, forcing me to explain every single line of my code. Please help me. Thanks! 回答1: ./ is a relative path which is relative to the current working directory of your process. In computing, the working

How can I list all files in a directory sorted alphabetically using PHP?

帅比萌擦擦* 提交于 2020-04-05 15:52:27
问题 I'm using the following PHP code to list all files and folders under the current directory: <?php $dirname = "."; $dir = opendir($dirname); while(false != ($file = readdir($dir))) { if(($file != ".") and ($file != "..") and ($file != "index.php")) { echo("<a href='$file'>$file</a> <br />"); } } ?> The problem is list is not ordered alphabetically (perhaps it's sorted by creation date? I'm not sure). How can I make sure it's sorted alphabetically ? 回答1: The manual clearly says that: readdir

Opendir function gives me multiple arrays instead of just one

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-06 12:51:26
问题 Salutations, Elders of code, I am on a quest to master the spells of PHP, and now need your assistance in slaying a mighty beast. I'm making a REST API in PHP. One of the functions is a GET that returns a list of pngs in a dir. But instead of returning one array, it returns multiple arrays (one for each iteration?). I want: ["1.png","2.png","3.png"] But I'm getting: ["1.png"]["1.png","2.png"]["1.png","2.png","3.png"] I present my pitiful function for scorn and humiliation: function getPics()

PHP permission Denied using unlink and rmdir

二次信任 提交于 2020-01-05 11:47:05
问题 i've been trying to figure out why my Php code is giving me a annoying error. I've tried countless functions from previous post but the error its been giving is "Permission Denied". From my understanding either i have to have special privledges to delete files, etc.. I've tried multiple solutions but I'm still getting this error. If anyone can point me in the right direction, that'll be great. Ive post a snippet of my code below.. Thanksss $first_sub = "my_dir"; if(is_dir($first_sub)){ $read

How to search file in folder by using php?

落花浮王杯 提交于 2020-01-05 07:32:03
问题 I have a folder called allfiles , and there are some files in this folder, such as 1212-how-to-sddk-thosd.html 3454-go-to-dlkkl-sdf.html 0987-sfda-asf-fdf-12331.html 4789-how-to-fdaaf-65536.html I use scandir to list all files, and now I need to find the file by with keywords, example to-dlkkl is the keyword, and I will get the file 3454-go-to-dlkkl-sdf.html . Glob seems not work, and opendir and readdir are not work well, any ideas? 回答1: Use loop foreach and strpos function: $files = scandir

How to search file in folder by using php?

雨燕双飞 提交于 2020-01-05 07:31:51
问题 I have a folder called allfiles , and there are some files in this folder, such as 1212-how-to-sddk-thosd.html 3454-go-to-dlkkl-sdf.html 0987-sfda-asf-fdf-12331.html 4789-how-to-fdaaf-65536.html I use scandir to list all files, and now I need to find the file by with keywords, example to-dlkkl is the keyword, and I will get the file 3454-go-to-dlkkl-sdf.html . Glob seems not work, and opendir and readdir are not work well, any ideas? 回答1: Use loop foreach and strpos function: $files = scandir

How to sort by date using PHP opendir()

↘锁芯ラ 提交于 2019-12-25 07:36:58
问题 I have a directory full of files that I am trying to echo out. If the file is an image, the image itself is echoed out. If the file is not an image, the name of the file is echoed out. This code below works perfectly however I can't seem to get the order sorted by date. The files are randomly echoed out. How would I make it so that the files are sorted by last modified (latest first). <?php $blacklist = array("index.php"); $ext = pathinfo($files, PATHINFO_EXTENSION); if ($handle = opendir('.'

opendir will not accept string variable but will accept plain string

扶醉桌前 提交于 2019-12-24 04:08:15
问题 I cannot get this function to work, because for some reason opendir will not take buffer2 (declared as char buffer2[128]) as an argument properly. If I replace the variable with something like "." or "sample", it works perfectly. But doing it like this, I get a segmentation fault every time. Please help. system("clear"); DIR *dirp; struct dirent *dp; printf("Enter directory name: "); fgets(buffer2, 100, stdin); if((dirp = opendir(buffer2)) == NULL) printf("Could not open directory\n"); while(

Opendir error; No such file or directory found

北战南征 提交于 2019-12-22 08:41:02
问题 This may be a very easy question. I am working in directory /mobile and I have photos in a directory /uploads. I am getting the error: Warning: opendir(http://www.yoozpaper.com/uploads) [function.opendir]: failed to open dir: not implemented in /hermes/bosweb/web088/b881/ipg.yoozpapercom/mobile/sportspage.php on line 313 I am putting this into a variable $dir = "http://www.yoozpaper.com/uploads" for the image src=$dir/$file . Note that this is working when I am working with files in the main

Accessing Directories in C

会有一股神秘感。 提交于 2019-12-17 20:42:03
问题 The program is to open a directory and to display the name of the files... i.e if there is a file..it should say FILE....else DIRECTORY.. but the program displays all the files as directory.. Could anyone pls check the code for any errors....thnx #include<stdio.h> #include<dirent.h> #define DIR_path "root/test" main() { DIR *dir; dir=opendir(DIR_PATH); printf("THe files inside the directory :: \n"); struct dirent *dent; if(dir!=NULL) { while((dent=readdir(dir))) { FILE *ptr; printf(dent->d