views:

136

answers:

1

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.

+1  A: 

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();
        }
benjamin
After re-reading your question I see that the file contains a list of 2 filenames, in that case you want to read the full data from the first column by making another streamreader and then create the file with the name of the second column and add some addition text to the stream before you write it back out. All the pieces are there in the code above you just have to move them around a little.
benjamin
Thank you very much! I was only expecting a pointing in the right direction, but I certainly appreciate the code even more! Thank you for your time and knowledge!
quasiChaos