获取目录名称列表并输出到文件
我正在寻找 Windows 计算机获取目录列表、将结果输出到格式化文本文件的最佳方法,然后我可以用它来进行 SQL 更新。
目录格式为:
/<Category-Name>/img.jpg
或
/<Category-Name>/images/*.jpg
/<Category-Name>/thumbnails/*.jpg
或
/<Category-Name>/full/*.jpg
/<Category-Name>/thumb/*.jpg
我正在考虑的是一个输出文件,其中包含:
<Category-Name>,f,blah1.jpg
<Category-Name>,f,blah2.jpg
<Category-Name>,t,blah3.jpg
etc...
我的限制是我无法使用 Linux 计算机,也无法访问 Linux 计算机,例如 cat
。因此,我决定 C# 和 .Net 框架是实现这一目标的最佳选择。我相信 Python 或 Perl 也可以,但我还没有学习任何一种语言。
非常欢迎任何有关如何编写此类程序的建议或有关如何解决此问题的其他想法。
需要明确的是,我的目的是获取一个目录列表,其中所有文件都以“.jpg”结尾,并输出到文本文件,以便我可以操作在数据库中创建 SQL INSERT。通过编程来完成此任务比通过内容管理系统为此任务和未来任务制作每个条目所需的时间要少得多。这些目录很容易就有数千个。
I am looking for the best method for a windows computer to grab a directory listing, output the result to a formatted text file I can then use to make a SQL update.
Directories are formated:
/<Category-Name>/img.jpg
or
/<Category-Name>/images/*.jpg
/<Category-Name>/thumbnails/*.jpg
or
/<Category-Name>/full/*.jpg
/<Category-Name>/thumb/*.jpg
What I was considering is a output file containing:
<Category-Name>,f,blah1.jpg
<Category-Name>,f,blah2.jpg
<Category-Name>,t,blah3.jpg
etc...
My limitations are that I am not on, nor do I have access to a Linux computer for nifty tools such as cat
. So I have decided C# and the .Net framework are my best bet to accomplish this. I believe Python or Perl would do just as well but I have yet to learn either language.
Any suggestions on how to write such a program or other ideas on how to tackle this are most welcome.
To be clear, my intentions are to get a directory listing with files all ending in '.jpg' outputted to a text file in a way that I can manipulate to create an SQL INSERT into a database. Programming something to accomplish this would take considerably less time than making each entry through a Content Management system for this and future tasks. The directories are easily in the thousands.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
DirectoryInfo 应该为您提供所需的内容 - http://msdn. microsoft.com/en-us/library/system.io.directoryinfo.aspx
DirectoryInfo should give you what you need -- http://msdn.microsoft.com/en-us/library/system.io.directoryinfo.aspx
您可以使用 Linq-to-FileSystem 查询目录,列出所有文件夹、文件和子文件夹。下面的文章演示了 API:
http://www.codeproject.com/KB/ linq/LinqToTree.aspx#filesystem
You could use Linq-to-FileSystem to query a directory, listing all the folders, files and sub-folders. The article below demonstrates the API:
http://www.codeproject.com/KB/linq/LinqToTree.aspx#filesystem