FSO read in?
-
Hello, I have a big problem. I need to loop every file in the folder for *.gif image. I dont now there namnes. When I have find a image file I need to read in a *.txt with the same name exept for the *.txt. Now to the problem I have a loop that find the *.gif image and now I want to read in the text in the text file with the same namn but it is a *.txt how can I do that. If someone have any exemple it should be create. Thank.
-
Hello, I have a big problem. I need to loop every file in the folder for *.gif image. I dont now there namnes. When I have find a image file I need to read in a *.txt with the same name exept for the *.txt. Now to the problem I have a loop that find the *.gif image and now I want to read in the text in the text file with the same namn but it is a *.txt how can I do that. If someone have any exemple it should be create. Thank.
i would do something like -
foreach (string s in System.IO.Directory.GetFiles(@"c:\dir", "*.gif")) { string txtPath = s.Substring(0, s.Length - 3) + "txt"; System.IO.TextReader tr = new System.IO.StreamReader(txtPath); string text = tr.ReadToEnd(); tr.Close(); }
-
i would do something like -
foreach (string s in System.IO.Directory.GetFiles(@"c:\dir", "*.gif")) { string txtPath = s.Substring(0, s.Length - 3) + "txt"; System.IO.TextReader tr = new System.IO.StreamReader(txtPath); string text = tr.ReadToEnd(); tr.Close(); }
-
i would do something like -
foreach (string s in System.IO.Directory.GetFiles(@"c:\dir", "*.gif")) { string txtPath = s.Substring(0, s.Length - 3) + "txt"; System.IO.TextReader tr = new System.IO.StreamReader(txtPath); string text = tr.ReadToEnd(); tr.Close(); }
Well this is the code I have! <% Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.GetFolder(Server.MapPath("/test/")) Set fc = f.Files For Each f1 in fc if right(lcase(f1.name),4) = ".gif" then Response.Write("
") Next %> And in this code I need to read in the text file so the image is ahown and then the text. How do I do that with the code you give me?
-
Well this is the code I have! <% Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.GetFolder(Server.MapPath("/test/")) Set fc = f.Files For Each f1 in fc if right(lcase(f1.name),4) = ".gif" then Response.Write("
") Next %> And in this code I need to read in the text file so the image is ahown and then the text. How do I do that with the code you give me?
are you using asp.net or asp 3? cause the code i have given you will only work in asp.net. if you wanted to do this in asp 3 you would have to have do something like:
'get the file path - Set txtFilePath = Replace(f1.name, right(lcase(f1.name),4), ".txt") 'then read the file using fso dim txtStream Set txtStream = fso.OpenTextFile(txtFilePath, fsoForReading) 'the write the string out Response.Write txtStream.ReadAll txtStream.Close
im a bit rusty in this area but this should give you more or less an idea!