使用文件名列表创建文件并向每个文件添加内容

发布于 2024-07-21 18:46:10 字数 371 浏览 17 评论 0原文

我需要制作一堆重定向页面,因为我最近更新了我的网站,该网站以前使用 .html 文件,现在所有文件都是 .aspx。 我有一个制表符分隔的文件,其中包含原始文件名列表和相应的新文件名。

似乎应该有一种语言,我应该能够使用第一列作为文件名创建一个文件,并插入第二列作为其内容以及一些用于 301 重定向的附加文本。

有人可以为我指出正确的方向,即哪种语言能够实现这一目标吗? 另外,如果您还可以指出我将使用的方法/函数的名称,这样我就知道创建文件时从哪里开始。

我需要多次做此类事情,并且愿意学习一门新语言(Perl、Python 或其他语言)来完成此任务,但我只需要指明正确的方向。 我使用Windows XP进行开发。

感谢您的时间。

I need to make a bunch of redirect pages as I've recently updated my web site which previously used .html files and now all the files are .aspx. I have a tab-delimited file containing a list of original filenames and the corresponding new filename.

It seems like there should be a language out there that I should be able to create a file using the first column for the filename and insert the second column as its content with some additional text for the 301 redirect.

Could someone point me in the right direction as to what language(s) would be able to accomplish this? Also, if you could also point out the name of the method/function I would be using so I know where to begin when creating the file.

I've needed to do this type of thing many times and am willing to learn a new language (Perl, Python, or whatever) to accomplish this, but I just need pointed in the right direction. I am using Windows XP to develop on.

Thank you for your time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谜泪 2024-07-28 18:46:11

如果您已经在使用 aspx,则可以通过几行 C# 来完成此操作,您可以在虚拟页面的代码隐藏中对其进行处理。

System.IO.StreamReader myreader = new System.IO.StreamReader(Server.MapPath("~/Text.txt"));
        while (!myreader.EndOfStream)
        {
            //9 is Ascii value of Tab  bad idea to split if the second set of values might contain tabs but can reconstruct the data if inputString.length >2
            string[] inputString = myreader.ReadLine().Split(char.ConvertFromUtf32(9).ToCharArray());
            //construct the path to where you want to save the file, or if the filename is the full path all the better
            System.IO.StreamWriter filemaker = new System.IO.StreamWriter(@"C:\" + inputString[0]);
            filemaker.Write(inputString[1]);
            filemaker.Close();
        }

This can be done in a few lines of C# if you already are working with aspx you can process this in the codebehind on a dummy page.

System.IO.StreamReader myreader = new System.IO.StreamReader(Server.MapPath("~/Text.txt"));
        while (!myreader.EndOfStream)
        {
            //9 is Ascii value of Tab  bad idea to split if the second set of values might contain tabs but can reconstruct the data if inputString.length >2
            string[] inputString = myreader.ReadLine().Split(char.ConvertFromUtf32(9).ToCharArray());
            //construct the path to where you want to save the file, or if the filename is the full path all the better
            System.IO.StreamWriter filemaker = new System.IO.StreamWriter(@"C:\" + inputString[0]);
            filemaker.Write(inputString[1]);
            filemaker.Close();
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文