Results 1 to 2 of 2

Thread: Replace all files in directory/subdirectory recursive

  1. #1

    Thread Starter
    Member otherones's Avatar
    Join Date
    Jun 2002
    Location
    Milk Factory
    Posts
    59

    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.
    CSC

  2. #2

    Thread Starter
    Member otherones's Avatar
    Join Date
    Jun 2002
    Location
    Milk Factory
    Posts
    59

    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:
    1. Public Function LoadDirectory(ByVal DirectoryPath As String)
    2.         Try
    3.             Dim x As Integer = 0
    4.             Dim xPath() As String = Directory.GetDirectories(DirectoryPath)
    5.             Dim xFiles() As String = Directory.GetFiles(DirectoryPath)
    6.  
    7.             xPath.Sort(xPath)
    8.             xFiles.Sort(xFiles)
    9.  
    10.             For x = 0 To UBound(xPath)
    11.                 Dim xDir() As String = Split(xPath(x), "\")
    12.  
    13.                 Debug.Write(Microsoft.VisualBasic.Strings.Space(UBound(xDir) * 2) & xDir(UBound(xDir)) & " [DIR]" & vbCrLf)
    14.  
    15.                 LoadDirectory(DirectoryPath & "\" & xDir(UBound(xDir)))
    16.             Next
    17.             ' Loop thru all files in the current Directory
    18.             For x = 0 To UBound(xFiles)
    19.                 Dim xDir() As String = Split(xFiles(x), "\")
    20.                 Dim s As System.IO.StreamWriter
    21.  
    22.                 File.Delete(xFiles(x))
    23.  
    24.                 s = File.CreateText(xFiles(x))
    25.                 s.Write("THE NEW TEXT OF THIS FILE " + Path.GetFileName(xFiles(x)))
    26.                 s.Close()
    27.  
    28.                 Debug.Write(Microsoft.VisualBasic.Strings.Space(UBound(xDir) * 2) & Path.GetFileName(xFiles(x)) & vbCrLf)
    29.             Next
    30.         Catch
    31.             Debug.Write("UNABLE TO READ DIRECTORY" & vbCrLf)
    32.         End Try
    33.     End Function
    CSC

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width