日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

Windows系统C语言获取文件夹来的所有文件名的方法

發布時間:2025/5/22 windows 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Windows系统C语言获取文件夹来的所有文件名的方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Windows系統C語言獲取文件夾來的所有文件名的方法,代碼如下:

#include <io.h> #include <stdio.h> #include <direct.h>#define MAX_LEN 4096int main(void) {char root[] = "E:\\Workspace";struct _finddata_t file;intptr_t hFile;char buf[MAX_LEN];if (_chdir(root)){printf("打開文件夾失敗: %s\n", root);return 1;}hFile = _findfirst("*.c", &file);while (_findnext(hFile, &file) == 0){sprintf_s(buf, MAX_LEN, "%s\\%s", root, file.name);printf("%s\n", buf);}return 0; }

下面是網友提供的方案,僅供參考:

#include <windows.h> #include <tchar.h> #include <stdio.h>#define BUFSIZE 4096 #define LONG_DIR_NAME TEXT("c:\\longdirectoryname")void _tmain(int argc, TCHAR *argv[]) {DWORD retval=0;BOOL success; TCHAR buffer[BUFSIZE]=TEXT(""); TCHAR buf[BUFSIZE]=TEXT(""); TCHAR** lppPart={NULL};if( argc != 2 ){_tprintf(TEXT("Usage: %s [file]\n"), argv[0]);return;}// Retrieve the full path name for a file. // The file does not need to exist.retval = GetFullPathName(argv[1],BUFSIZE,buffer,lppPart);if (retval == 0) {// Handle an error condition.printf ("GetFullPathName failed (%d)\n", GetLastError());return;}else {_tprintf(TEXT("The full path name is: %s\n"), buffer);if (lppPart != NULL && *lppPart != 0){_tprintf(TEXT("The final component in the path name is: %s\n"), *lppPart);}}// Create a long directory name for use with the next two examples.success = CreateDirectory(LONG_DIR_NAME,NULL);if (!success){// Handle an error condition.printf ("CreateDirectory failed (%d)\n", GetLastError());return;}// Retrieve the short path name. retval = GetShortPathName(LONG_DIR_NAME,buf,BUFSIZE);if (retval == 0) {// Handle an error condition.printf ("GetShortPathName failed (%d)\n", GetLastError());return;}else _tprintf(TEXT("The short name for %s is %s\n"), LONG_DIR_NAME, buf);// Retrieve the long path name. retval = GetLongPathName(buf,buffer,BUFSIZE);if (retval == 0) {// Handle an error condition.printf ("GetLongPathName failed (%d)\n", GetLastError());return;}else _tprintf(TEXT("The long name for %s is %s\n"), buf, buffer);// Clean up the directory.success = RemoveDirectory(LONG_DIR_NAME);if (!success){// Handle an error condition.printf ("RemoveDirectory failed (%d)\n", GetLastError());return;} }

?

總結

以上是生活随笔為你收集整理的Windows系统C语言获取文件夹来的所有文件名的方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。