① 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中如何获取文件上传进度
前端html5支持获取上传的字节数,同时也能获取总字节大小。这样可以算出进度。
node.js的后端request一般支持流模式,于是就可以用request.on('data', () => {})获取到已上传的字节大小,前端获取总字节大小之后可以将信息放进request header里。这样也可以算出进度