hadoop查看目录大小 如何将hdfs里某一目录下的所有文件的文件名读取出来
如何将hdfs里某一目录下的所有文件的文件名读取出来
如何将hdfs里某一目录下的所有文件的文件名读取出来
默认是从hdfs读取文件,也可以指定sc.textFile("路径").在路径前面加上hdfs:表示从hdfs文件系统上读
本地文件读取 sc.textFile("路径").在路径前面加上file: 表示从本地文件系统读,如file:/home/user/spark/README.md
C++读取某一目录下的所有文件名
我写了个,用到了MFC的CString和CFileFind,不知道是不是你想要的。
#include <afxwin.h> project->settings->general->Use MFC in a shared DLL
#include <iostream>
using namespace std;
void FindAllFile(CString path, CString* filenames, int& count)
{
CFileFind finder;
BOOL working = finder.FindFile(path + "\*.*");
while (working)
{
working = finder.FindNextFile();
if (finder.IsDots())
continue;
if (finder.IsDirectory())
{
FindAllFile(finder.GetFilePath(), filenames, count);
}
else
{
CString filename = finder.GetFileName();
filenames[count++] = filename;
}
}
}
int main(int argc, char* argv[])
{
CString filenames[1024];
int count = 0;
char path[MAX_PATH];
while (cin >> path) { . for current directory, empty for root directory
FindAllFile(path, filenames, count);
for (int i = 0; i < count; i++)
cout << (LPCSTR)(filenames[i].GetBuffer(filenames[i].GetLength())) << endl;
}
return 0;
}
VB问题:如何读取、返回某一目录下的所有文件名?
控件:按钮一个 列表框一个 Function SearchFiles(Path As String, FileType As String) Dim Files() As String '文件路径 Dim Folder() As String '文件夹路径 Dim a, b, c As Long Dim sPath As String sPath = Dir(Path & FileType) '查找第一个文件 Do While Len(sPath) '循环到没有文件为止a = a + 1ReDim Preserve Files(1 To a) Files(a) = Path & sPath '将文件目录和文件名组合,并存放到数组中 List1.AddItem Files(a) '加入list控件中 sPath = Dir '查找下一个文件 DoEvents '让出控制权LoopsPath = Dir(Path & "", vbDirectory) '查找第一个文件夹 Do While Len(sPath) '循环到没有文件夹为止 If Left(sPath, 1) < "." Then '为了防止重复查找 If GetAttr(Path & "" & sPath) And vbDirectory Then '如果是文件夹则。。。。。。 b = b + 1ReDim Preserve Folder(1 To b) Folder(b) = Path & sPath & "" '将目录和文件夹名称组合形成新的目录,并存放到数组中End IfEnd IfsPath = Dir '查找下一个文件夹 DoEvents '让出控制权LoopFor c = 1 To b '使用递归方法,遍历所有目录 SearchFiles Folder(c), FileTypeNextEnd Function
看一下是不是这样?窗体上加驱动器列表框、目录列表框和文件列表框Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub Private Sub Form_Click()
For i = 0 To File1.ListCount
a = File1.List(i)
Print a
Next i
End Sub Private Sub Form_Load()
Drive1.Drive = "e:"
End Sub
不一定对,仅供参考!

函数原型:
int WINAPI icePub_getPathList(char *strCurrentPath,char *strPathList,int maxLen,int flag)
输入:strCurrentPath 待搜索路径名
maxLen strPathList最大长度
flag 信息标志,0 只文件名,1 文件长度
输出:strPathList 带全路径文件名
VB sample 代码:
Private Declare Function icePub_getPathList Lib "icePubDll.dll" (ByVal strCurrentPath As String, ByVal strPathList As String, ByVal maxLen As Integer, ByVal flag As Integer) As Integer
Dim a2 As Integer
Dim str1 As String
str1 = Space(1024 * 20 + 1)
a2 = icePub_getPathList("D:", str1, 1024 * 20, 1)
MsgBox str1
vb 读取某一目录下的所有文本文件
在弹出txt内容那里你可以用字符型数组保存起来
Private Sub Command1_Click()
Dim Str1 As String, Str2 As String, mPath As String, i As Integer, txt_str As String
Dim txt_num As Integer
txt_num = 0
mPath = "E:Program Files叮叮科技叮叮摩卡接收记录" '路径设置
Str1 = Dir(mPath & "*.txt") '查找类型
Do While Str1 <> ""
'Str2 = Left(Str1, InStr(Str1, ".") - 1)
txt_num = txt_num + 1
Str2 = Str1
Open mPath & Str2 For Binary As #txt_num '读取txt
txt_str = ""
txt_str = Space(LOF(txt_num))
Get #txt_num, , txt_str
MsgBox txt_str '弹出txt的内容
Close #txt_num
Kill mPath & Str2 '删除txt文件
Str1 = Dir
Loop
End Sub
如何用C++读取未知文件名的文件(用C++程序依次读取某一目录下的所有文件)
随便写的大概的思路吧,没编译过可以会有错:
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
BOOL fFinished = FALSE;
char FindPath[]={"C:\Text\*.*"};搜索路径
char Key[]="找";关键字
FILE *pFile;
char *pBuf;
DWORD dwSize;
hFind = FindFirstFile(FindPath, &FindFileData);开始一个搜索
if (hFind != INVALID_HANDLE_VALUE)
{
while (!fFinished)
{
pFile=fopen(FileData.cFileName,"r");
dwSize=GetFileSize(pFile,NULL);
pBuf=new char[dwSize+1];
fread(pBuf,1,dwSize,pFile);
if(strstr(Key,pBuf))
{
找到了然后干点什么
}
delete pBuf;
fclose(pFile);
if (!FindNextFile(hFind, &FileData))
{
if (GetLastError() == ERROR_NO_MORE_FILES)
{
MessageBox(hwnd, "No more .TXT files.","Search pleted.", MB_OK);
fFinished = TRUE;
}
}
}
FindClose(hFind);
}