从文件夹动态读取文件. [英] DYNAMICALLY READING FILES FROM A FOLDER.

查看:75
本文介绍了从文件夹动态读取文件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个要求,例如我在一个文件夹中有几个文件,它们的格式不同,例如.xls,.doc,.pdf等.我需要从该文件夹中读取每个文件.并且会有一些关键字可用,我需要在文件夹中所有可用的文件中搜索它们.因此,我需要显示该特定单词可用的页码,文件名,行号,单击单个结果时应突出显示该单词可用的位置.plz,请仔细阅读一些要求,并指导我开发该搜索引擎.在此先感谢您.

Hi,

I have requirement like i have several files in a folder in different formats like .xls,.doc,.pdf etc.I need to read each and every file from the folder.And there will be some bunch of keyword available,I need to search them in all the file avilable in the folder.And as a result i need to display page number,File name,Line number where that particular word is available and on click of a single result it should highlight the location where the word is Available.Plz some one go through the requrement and guide me to devellop this search engine.Thanks in advance.

推荐答案

您需要创建单独的API来读取每种文件格式.该API的输入应为Filename,返回文档应为搜索格式.

遵循步骤:

1.尝试读取所有文件名recusivelt并形成一个树状结构,如

-DOC
1.doc
2.doc
-PDF
1.PDF
2.PDF

2.现在,您需要为每种文件格式创建API,并且该API应该返回DOcument内容
3.存储与该文件对应的内容.
4.然后在内存中搜索集合中的内容.

希望这有助于您开始工作.

Senthil S
You need to create seperate API for reading each file format. The Input for that API should is Filename and it should return document is search format.

Step to follow:

1. Try to Read the all file name recusivelt and form one tree structure like

-DOC
1.doc
2.doc
-PDF
1.PDF
2.PDF

2. Now you need create API for each file format and the API should return the DOcument content
3. Store that Content Corresponging to that file.
4. Then Search for the content in the collection you are having in the memeory.

Hope this helps to start working to your requirment.

Senthil S


获取文件:
检查此.net工具:
Getting Files:
Check this .net facility:
Directory.Getfiles()

此函数将获取目录路径,并以字符串形式返回所有文件的路径数组.

在文件中搜索单词:
然后在循环中逐行读取文件,因为您必须返回特定的行.按

this function will take directory path and return the array of paths of all files as string.

Search Word in file:
Then in a loop read a file line by line because you have to return the particular line. by

File.ReadAllLines()

它将返回字符串数组,该字符串显示文件中的所有行.现在,迭代此数组并在所有行中逐个查找关键字.

可能会帮助您开始.

It will return array of string which shows all the lines in your file. Now iterate this array and find your keyword one by one in all lines.

May it will help you to start.


这篇关于从文件夹动态读取文件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆