Comparison of folder scans under the "Linux&windows" Windows system with Linux system implementations

Source: Internet
Author: User
Tags strcmp

1, the Windows system under the Implementation folder file scanning

The implementation code is as follows:

 
#include <stdio.h> #include <string.h> #include <io.h> #define Testfolderpath "./" void Scanfolder (c

Onst char* Folder_path);

	int main (int argc,char* argv[]) {scanfolder (Testfolderpath);
return 0; File scan under/** folder (Windows system) @param folder_path folder path */void Scanfolder (const char* folder_path) {_finddata_t file
	;

	Long LF;
	Char tempstr[256];
	strcpy (Tempstr,folder_path);

    strcat (TempStr, "*.*"); if (lf = _findfirst (TempStr, &file))!=-1 {while (_findnext) = = 0) {if lf,&file (strcmp, "..
			") ==0) {continue;
				} if (File.attrib = = _a_subdir) {char ttempstr[256];
				strcpy (Ttempstr,folder_path);
				strcat (Ttempstr,file.name);
				strcat (Ttempstr, "/");
				fprintf (stdout, "%s\n", ttempstr);
			Scanfolder (TTEMPSTR);
				else {fprintf (stdout, "%s%s\n", folder_path,file.name);
				/*unsigned int type = File.attrib;
				if (type = = _a_normal) fprintf (stdout, "normal file \ n"); else if (type = = _a_rdonly) fprintf (stdout, "read-only file \ n"); 
				else if (type = = _a_hidden) fprintf (stdout, "hidden file \ n"); 
				else if (type = = _a_system) fprintf (stdout, "System file \ n"); 
					else fprintf (stdout, "archive file \ n"); 
*/}} _findclose (LF);
 }

2, Linux system under the implementation of folder files under the scan

The implementation code is as follows:

 
/* $Id: SCANFOLDER.C,2012/06/10 17:53:29 sine exp$ * * #include <stdio.h> #include <stdlib.h> #include <d irent.h> #include <sys/stat.h> #include <string.h> #define FOLDERPATH "./" void Scan_folder (const char* F

Older_path);

	int main (int argc,char* argv[]) {scan_folder (FolderPath);
return 0; /** folder file Scan implementation @param folder_path folder path/void Scan_folder (const char* Folder_path) {/* Open a directory and create a directory stream that returns a pointer to Dir
	A pointer to the structure that is used to read the catalog data items.
	* * dir* DP = opendir (FOLDER_PATH);
		if (NULL = DP) {fprintf (stderr, "Cannot open directory:%s\n", folder_path);	
	return;
	} struct dirent *entry;

	struct stat statbuf;
		ChDir (folder_path);//cd directory Toggle/* Readdir Returns a pointer to a structure in which the resource for the next directory item in the directory flow is stored.
	Subsequent Readdir calls will return the subsequent directory entries.	

		*/while (NULL!= (entry = Readdir (DP)) {Lstat (ENTRY-&GT;D_NAME,&AMP;STATBUF); if (S_isdir (Statbuf.st_mode)) {if (strcmp (".", entry->d_name) = = 0 | | strcmp ("..", entry->d_name) = = 0) {C	
			Ontinue; } Char tempstr[256];
			strcpy (Tempstr,folder_path);
			strcat (Tempstr,entry->d_name);
			strcat (TempStr, "/");
			fprintf (stdout, "before:%s\n", tempstr);
		Scan_folder (TEMPSTR);	
		else {fprintf (stdout, "%s%s\n", folder_path,entry->d_name);

	} chdir ("..");
 Closedir (DP);//close a directory stream and release the resource associated with it}

Run Result:

./josephus.c

./scanfolder.c

./josephus

./readme.txt

./a.out

./test/test.txt

./makefile


to this end, we introduced the two systems under the implementation of the folder scan, write this here, is mainly convenient for future applications have a reference.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.