c# - Need to pull path info from file to create new file at same location -
I'm trying to cross a directory with thousands of sub-directories. Each subdirectory has an .nfo file < / P> I I'm using Xdocument to parse some information, and I need to create a new file at the same place. As the NFO file. I think I have all the basic parts, but I did not know how to create a new file in the same place as the source file . Even I have so far: missing the missing piece where is new file to save If so, take the D: \ Test \ D: \ Test \ Deira 1: D: \ Test \ DRI file 1. NO D: \ Test \ DER 2D: \ Test \ DR2 \ file2.nfo D: \ Test \ Dir3 \ D: \ Test \ Dir3 \ file3.nfo
D: \ Test \ D: \ Test \ Dira 1 \ D: \ Test \ DRI \ file1.nfo New File: D: \ Test \ Dear 1 Info .nfo D: \ Test \ Dir2 \ D: \ Test \ Dir2 \ file2.nfo New File: D: \ Test \ Dir2 \ info.nfo D: \ Test \ Dir3 \ D: \ Test \ Dir3 \ file3.nfo NEW FILE: D: \ Test \ Dir3 \ info.nfo
string strID = null; String [] filesNFO = directory Get files (@ "D: \ test \", "* .nfo", searchoptions, all directories); Fresh (string file NFO files) {var doc = XDocument.Load (file); StrID = doc.Root.Element ("id") == Faucet? "": doctor. Root.ediment ("id"). Values; File stream fs = new filestream ("info.nfo", FileMode.Create); StreamWriter Info = New Streamer (FS); Info.Write ("http://powerhostcrm.com/" + strID); Info.Close (); } file to filesNFO and grab the directory. I also recommend wrapping everything in using the statement:
string strID; String [] filesNFO = directory Get files (@ "D: \ test \", "* .nfo", searchoptions, all directories); Fresh (string file NFO files) {var doc = XDocument.Load (file); StrID = doc.Root.Element ("id") == Faucet? "": doctor. Route. Element ("id"). value; String directory = path. Gate directoryname (file); String infoNfo = Path.Combine (directory, "info.nfo"); Using {info.Write ("http://powerhostcrm.com/" + strID) using (var info = new streamwriter (fs)) (var fs = new FileStream (InfoNfo, FileMode.Create)); }}
Comments
Post a Comment