|
-
Aug 8th, 2002, 01:09 PM
#1
Thread Starter
Member
Replace all files in directory/subdirectory recursive
Hello.. I am moving my website (medium size ~50-60 megs) to a new server. However I am going to maintain my old site for a while.
What I want to do is write some code that will start at a particular directory, and replace each file (FILEX.html) with a new .html file that reads:
this page has moved, you can find it at www.newsite.com/FILEX.html
.. What is the best way to go through the starting directory, its subs, their subs, etc recursivly?
I had some problems doing this with an MP3 indexer i was building b/c I couldn't get it to recurse.. ( i think i was using the DIR() command, and it was global so wouldn't hold the variable for a recursion????)
any help would be appreciated.
-
Aug 9th, 2002, 03:51 PM
#2
Thread Starter
Member
figured it out
Well I figured it out.. if anyone is interested here is the code I used...
Once I figured out to work w/System.IO.Directory it was really easy.. but as I am new to .NET i did not know.
If anyone sees any improvements, please let me know..
BTW the basic idea of this script was borrow from:
http://www.planet-source-code.com/vb...=287&lngWId=10
VB Code:
Public Function LoadDirectory(ByVal DirectoryPath As String)
Try
Dim x As Integer = 0
Dim xPath() As String = Directory.GetDirectories(DirectoryPath)
Dim xFiles() As String = Directory.GetFiles(DirectoryPath)
xPath.Sort(xPath)
xFiles.Sort(xFiles)
For x = 0 To UBound(xPath)
Dim xDir() As String = Split(xPath(x), "\")
Debug.Write(Microsoft.VisualBasic.Strings.Space(UBound(xDir) * 2) & xDir(UBound(xDir)) & " [DIR]" & vbCrLf)
LoadDirectory(DirectoryPath & "\" & xDir(UBound(xDir)))
Next
' Loop thru all files in the current Directory
For x = 0 To UBound(xFiles)
Dim xDir() As String = Split(xFiles(x), "\")
Dim s As System.IO.StreamWriter
File.Delete(xFiles(x))
s = File.CreateText(xFiles(x))
s.Write("THE NEW TEXT OF THIS FILE " + Path.GetFileName(xFiles(x)))
s.Close()
Debug.Write(Microsoft.VisualBasic.Strings.Space(UBound(xDir) * 2) & Path.GetFileName(xFiles(x)) & vbCrLf)
Next
Catch
Debug.Write("UNABLE TO READ DIRECTORY" & vbCrLf)
End Try
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|