導航:首頁 > 文件處理 > node統計文件夾文件個數

node統計文件夾文件個數

發布時間:2022-08-12 14:10:19

① node.js如何快速統計一個txt文件行數

解決方法:

1、通過IE的FSO方法,不過該方法只有IE中可以使用

2、通過Ajax方式讀取文本,該方法通用,建議使用該方法

代碼示例:

$(document).ready(function(){
$("#b01").click(function(){//比如再按鈕的單擊事件中
htmlobj=$.ajax({url:"/jquery/test1.txt",async:false});//通過ajax讀取test1.txt文本文件。
$("#myDiv").html(htmlobj.responseText.replace(/.+/g,'</br>'));//根據回車換行符進行替換,替換成html換行符
});
});
<divid='myDiv'></div>
<inputtype='button'id='b01'value='讀取文本'/>

② 如何查看一個文件在namenode節點中元數據所佔的大小

1. namenode負責管理目錄和文件信息,真正的文件塊是存放在datanode上。 2. 每個map和rece(即task)都是java進程,默認是有單獨的jvm的,所以不可能同一個類的對象會在不同節點上。

③ 如何用python統計一個路徑下的文件總數

剛好剛才寫了一個

defget_dir_info(dir_path,deep=0,info=None):
ifinfoisNone:
info={'deep':0,'deep_dir':'','file_num':0,'dir_num':0}
ifdeep>info['deep']:
info['deep']=deep
info['deep_dir']=dir_path
file_list=os.listdir(dir_path)
forfileinfile_list:
file_path=os.path.join(dir_path,file)
ifos.path.isdir(file_path):
info['dir_num']+=1
get_dir_info(file_path,deep=deep+1,info=info)
else:
info['file_num']+=1
ifdeep==0:
returninfo

if__name__=='__main__':
dir_path="D:\Tools\WebStorm2016\plugins"
s=time.time()
d=get_dir_info(dir_path)
print("{}".format(time.time()-s))
print(d)

#所有的深度是基於給出的文件夾統計的
#deep_dir比較雞肋,因為如果有多個相同深度的文件夾就會替換掉只剩一個
#可以自行去掉這個功能

#deep:最深的層數
#deep_dir:最深的路徑名稱
#dir_num:文件夾數量
#file_num:文件數量

'''
0.21001195907592773
{'deep':12,'deep_dir':'D:\Tools\WebStorm2016\plugins\spy-js\server\node_moles\istanbul\node_moles\resolve\test\resolver\biz\node_moles\garply\lib','file_num':6325,'dir_num':1113}
'''

④ tsm伺服器中怎麼看各個node備份了哪些文件

問題分類
〖AIX專家坐診〗
主題標簽
TSM備份分布
狀態
發布時間:2009-12-29
更新時間:2009-12-29
會員瀏覽:4451
請教:TSM如何檢查某個node的備份分布
俺最在一直在研究TSM,碰到有不少問題,比如:
俺在TSM中設置了自動調度(FILE類型,incremental),在調度成功後
1、TSM如何檢查某個node的備份內容都分布在哪些volume上?
2、對於TSM備份成功的內容怎麼檢查其備份日誌,比方說我想知道昨晚上某個schele運行時到底備份了哪些文件...

3、如果我們手動備份某個目錄,備份成功後,在伺服器上能否查到相關的備份記錄(比如系統調度的都可以用q event * * 檢查)

我在ISC沒有找到相關的內容,qian1110能不能再細說一下。

另外對於第2點我檢查發現看客戶端的日誌文件即可:
2、對於TSM備份成功的內容怎麼檢查其備份日誌,比方說我想知道昨晚上某個schele運行時到底備份了哪些文件...
解:檢查Client日誌文件即可,如:/usr/tivoli/tsm/client/ba/bin64/dsmsched.log

⑤ 求C語言/C++程序 統計一個文件中字元串的個數(不是字元而是字元串)計算其概率。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct node{
char *str;
int cnt;
struct node *next;
}node;

node *create_list()
{
node *head=(node *)malloc(sizeof(node));
head->str=NULL;
head->cnt=0;
head->next=NULL;
return head;
}

void find_insert_list(node *head,char *word)
{
node *p=head;
while(p->next && strcmp(word,p->next->str)>0)
p=p->next;
if(p->next && strcmp(word,p->next->str)==0)
{
p->next->cnt++;
head->cnt++;
}
else
{
node *t=(node *)malloc(sizeof(node));
t->str=(char *)malloc(sizeof(char)*(strlen(word)+1));
strcpy(t->str,word);
t->cnt=1;
head->cnt++;
t->next=p->next;
p->next=t;
}
}

void destroy_list(node *head)
{
node *p;
do{
p=head->next;
free(head->str);
free(head);
head=p;
}while(head);
}

void main()
{
node *head=create_list(),*p;
FILE *fp;
char str[81];

if((fp=fopen("C:/1.txt","r"))==NULL)
{
printf("open file error!\n");
exit(1);
}
while(!feof(fp))
{
fscanf(fp,"%s",str);
find_insert_list(head,str);
}

p=head->next;
while(p)
{
printf("%s:%d,%f\n",p->str,p->cnt,1.0*p->cnt/head->cnt);
p=p->next;
}

destroy_list(head);
}

⑥ 用nodejs怎麼獲得一個文件夾下面的視頻信息呢(具體指視頻時長/多少分鍾的視頻)

我知道的跟nodejs關系不大,可以用ffmpeg來獲取,然後nodejs調用ffmpeg的命令

⑦ C/C++編程遍歷文件夾,統計當前文件個數,輸出文件名

標准C是沒有目錄相關的函數的
CFree是16位的吧,那就更不用想了.貌似只能內嵌匯編使用dos中斷來完成.

還是換編譯器吧devcpp codeblock vc8 之類的都很好

【cmail】:
這個要用到windows API

HANDLE FindFirstFile(
LPCTSTR lpFileName,
LPWIN32_FIND_DATA lpFindFileData
);

BOOL FindNextFile(
HANDLE hFindFile,
LPWIN32_FIND_DATA lpFindFileData
);

WIN32_FIND_DATA

【CHROX】:
在Win32平台下不用windows api,有好多功能實現起來都很費勁,特別是系統相關的
再說用api又不是什麼丟人的事。開發可移植程序除外。
用FindFirstFile和FindNextFile兩個api很容易實現
////////////////////////////////////////////////
void FindFile(LPCTSTR lpszPath) {
TCHAR szFind[MAX_PATH];
lstrcpy(szFind,lpszPath);

if(!IsRoot(szFind)) lstrcat(szFind,"\\");
lstrcat(szFind,"*.*");
WIN32_FIND_DATA wfd;
HANDLE hFind=FindFirstFile(szFind,&wfd);

if(hFind==INVALID_HANDLE_VALUE) return;
do{
if(lstrcmp(wfd.cFileName,".")==0||lstrcmp(wfd.cFileName,"..")==0) continue;
char szFile[MAX_PATH];
lstrcpy(szFile,lpszPath);
if(!IsRoot(szFile)) lstrcat(szFile,"\\");
lstrcat(szFile,wfd.cFileName);
if((GetFileAttributes(szFile)&FILE_ATTRIBUTE_DIRECTORY)==FILE_ATTRIBUTE_DIRECTORY){
FindFile(szFile); //遞歸
}
else {
} //Do your things
}
} while (FindNextFile(hFind,&wfd));
CloseHandle(hFind);
}

【Geomatic】:
原來FindFirstFile和FindNextFile是WINDOWS的API 我暈 我以為是C++的函數庫里的東西呢
我明白了 我找到的代碼和CHROX的差不多
#include <stdio.h>
#include <windows.h>

BOOL IsRoot(LPCTSTR lpszPath)
{
TCHAR szRoot[4];
wsprintf(szRoot, "%c:\\", lpszPath[0]);
return (lstrcmp(szRoot, lpszPath) == 0);
}

void FindInAll(::LPCTSTR lpszPath)
{TCHAR szFind[MAX_PATH];<br>lstrcpy(szFind, lpszPath);<br>if (!IsRoot(szFind))<br>lstrcat(szFind, "\\");<br>lstrcat(szFind, "*.*"); // 找所有文件<br>WIN32_FIND_DATA wfd;<br>HANDLE hFind = FindFirstFile(szFind, &wfd);<br>if (hFind == INVALID_HANDLE_VALUE) // 如果沒有找到或查找失敗<br>return;<br><br>do<br>{<br>if (wfd.cFileName[0] == '.')<br>continue; // 過濾這兩個目錄<br>if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)<br>{<br>TCHAR szFile[MAX_PATH];<br>if (IsRoot(lpszPath))<br>wsprintf(szFile, "%s%s", lpszPath, wfd.cFileName);<br>else<br>wsprintf(szFile, "%s\\%s", lpszPath, wfd.cFileName);<br>FindInAll(szFile); // 如果找到的是目錄,則進入此目錄進行遞歸<br>}
else
{
TCHAR szFile[MAX_PATH];
if (IsRoot(lpszPath))
wsprintf(szFile, "%s%s", lpszPath, wfd.cFileName);
else
wsprintf(szFile, "%s\\%s", lpszPath, wfd.cFileName);
printf("%s\n",szFile);
// 對文件進行操作
}
} while (FindNextFile(hFind, &wfd));
FindClose(hFind); // 關閉查找句柄

}
int main(int argc, char* argv[])
{
FindInAll("g://music");
return 0;
}
謝謝大家的幫助

【Geomatic】:
這個怎麼給你們給分啊
那個分有用嗎
剛申請的 好多功能不會用啊

【cmail】:
點上面的「管理」。

【CHROX】:
分可是個好東西。呵呵,你以後就明白了。

【jixingzhong】:
DEV C++, 利用鏈表實現目錄內所有文件列表顯示

#include <stdio.h>
#include <dirent.h>
/*#include <alloc.h>*/
#include <string.h>

void main(int argc,char *argv[])
{
DIR *directory_pointer;
struct dirent *entry;
struct FileList
{
char filename[64];
struct FileList *next;
}start,*node;
if (argc!=2)
{
printf("Must specify a directory\n");
exit(1);
}
if ((directory_pointer=opendir(argv[1]))==NULL)
printf("Error opening %s\n",argv[1]);
else
{
start.next=NULL;
node=&start;
while ((entry=readdir(directory_pointer))!=NULL)
{
node->next=(struct FileList *)malloc(sizeof(struct FileList));
node=node->next;
strcpy(node->filename,entry->d_name);
node->next=NULL;
}
closedir(directory_pointer);
node=start.next;
while(node)
{
printf("%s\n",node->filename);
node=node->next;
}
}
}

【jixingzhong】:
linux下面的,作者不是我

A Demo written by camelrain

/*
the program find a file from current directory or your defined directory
commond optinon [path] filename
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <pwd.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

#define LENGTH 256

/* just if is a directory*/
static int IsDir (char * name);
/* search target file, arg1 is current path, arg2 is target file*/
static void search_file (char * path, char * name);

static int search_flag=0;

/*just if is a directory*/
static int IsDir (char * name) {
struct stat buff;

if (lstat(name,&buff)<0)
return 0; //if not exist name ,ignore

/*if is directory return 1 ,else return 0*/
return S_ISDIR(buff.st_mode);
}

/*search target file*/
static void search_file (char * path, char * name) {
DIR *directory;
struct dirent * dir_entry;
char buffer[LENGTH];

if ((directory=opendir(path)) == NULL) {
fprintf(stderr, "%s", path);
perror(" ");
return;
}

while (dir_entry=readdir(directory)) {
if (!strcmp(dir_entry->d_name,".")||!strcmp(dir_entry->d_name,"..")) {
/* do nothing*/
}
else {
/* if is boot directory add "/" */
if ((strcmp(path,"/"))==0)
sprintf(buffer,"%s%s",path,dir_entry->d_name);
/* if is not boot directory do not add "/"*/
else
sprintf(buffer,"%s/%s",path,dir_entry->d_name);

//printf("Now file : %s\n",buffer);
if (IsDir(buffer))
search_file (buffer , name);
else {
if (strcmp(dir_entry->d_name,name)==0)
{
printf("%s\n",buffer);
search_flag=1;
}
}
}
}
closedir(directory);
}

int main(int argc, char *argv[])
{
static char * current_dir;
static char * filename;
int length;

if (argc==1) {
printf("A few parameters!!\n");
return 0;
}

if (argc==2) {
current_dir=(char * )getcwd(current_dir,LENGTH);
filename=argv[1];
}

if (argc==3) {
length=strlen(argv[1]);

if (length>1 && (argv[1][length-1]=='/')) {
argv[1][length-1]='\0';
//printf("%d\n",strlen(argv[1]));
}

current_dir=argv[1];
filename=argv[2];
}

search_file(current_dir,filename);

if (!search_flag)
printf("Not found this(%s) file!\n",filename);

return 0;
}

【jixingzhong】:
VC 下的:

long handle;
struct _finddata_t filestruct;
char path_search[_MAX_PATH];
handle = _findfirst("目錄",&filestruct);
if((handle == -1)) return;
if( ::GetFileAttributes(filestruct.name)& FILE_ATTRIBUTE_DIRECTORY )
{
if( filestruct.name[0] != '.' )
{
_chdir(filestruct.name);
Search_Directory(szFilename);
_chdir("..");
}
}
else
{
if( !stricmp(filestruct.name, szFilename) )
{
strcat(path_search,"\\");
strcat(path_search,filestruct.name);
MessageBox(path_search);
}
}
while(!(_findnext(handle,&filestruct)))
{
if( ::GetFileAttributes(filestruct.name) &FILE_ATTRIBUTE_DIRECTORY )
{
if(*filestruct.name != '.')
{
_chdir(filestruct.name);
Search_Directory(szFilename);
_chdir("..");
}
else
{
if(!stricmp(filestruct.name,szFilename))
{
_getcwd(path_search,_MAX_PATH);
strcat(path_search,"\\");
strcat(path_search,filestruct.name);
MessageBox(path_search);
}
}
}
_findclose(handle);
}

⑧ 在Node.js中如何獲取文件上傳進度

  1. 前端html5支持獲取上傳的位元組數,同時也能獲取總位元組大小。這樣可以算出進度。

  2. node.js的後端request一般支持流模式,於是就可以用request.on('data', () => {})獲取到已上傳的位元組大小,前端獲取總位元組大小之後可以將信息放進request header里。這樣也可以算出進度

閱讀全文

與node統計文件夾文件個數相關的資料

熱點內容
androidhttpmime 瀏覽:774
威科夫操盤法pdf 瀏覽:981
演算法可以用圖表表示 瀏覽:948
山西太原php 瀏覽:273
常用cmd網路命令 瀏覽:676
hashmap7源碼分析 瀏覽:898
搜索引擎原理技術與系統pdf 瀏覽:361
運動估計演算法python 瀏覽:860
java正則1 瀏覽:538
redhatlinux最新 瀏覽:182
python字典編程詞彙 瀏覽:147
微信和伺服器如何通訊 瀏覽:13
百家號伺服器配置有什麼用 瀏覽:600
怎麼為電腦加密 瀏覽:59
伺服器出現差錯是什麼意思 瀏覽:619
蘋果app移到商店裡怎麼刪掉 瀏覽:257
phpjsphtml 瀏覽:66
吃雞手機國際服伺服器超時怎麼辦 瀏覽:69
努比亞Z5無命令 瀏覽:642
展示網站雲伺服器 瀏覽:872