0

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

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

有人可以为我指出正确的方向,什么语言可以做到这一点吗?此外,如果您还可以指出我将使用的方法/函数的名称,那么我知道在创建文件时从哪里开始。

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

感谢您的时间。

4

1 回答 1

1

这可以在几行 C# 中完成,如果您已经在使用 aspx,您可以在虚拟页面上的代码隐藏中处理它。

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();
        }
于 2009-05-22T22:29:11.990 回答