Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

VB.NET Moving/Deleting Files

Options
  • 10-02-2005 12:11am
    #1
    Closed Accounts Posts: 34


    This is probably easy for anyone who has a clue about VB.NET.
    I want to copy some files from one folder into another then delete the files in the source folder.

    I was messing around with file.copy but it wants 1 source file name and a destenation filename, i was trying things like *.* but it wouldn't work
    I can only get it to copy one file and i have to give it a filename in the new folder.

    How do i copy all the files in lets say "c:\mymusic\" to "c:\paulsmusic\"
    in one go, then i have to delete all the files in "c:\mymusic\"

    Thanks for any help in advance
    Jack


Comments

  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    Jack,

    Off the top of my head, (don't know .net too well), there should be a function to loop through the files in a specified folder. You should be able to get the file name from that list.

    Within this loop you would use the file.copy to copy the file.

    Here is some pseudo code:
    <%
    Dim myFileList ' object that returns the list of files in the specified folder
    Dim sOldFolder = "c:\old\"
    Dim sNewFolder = "c:\new\"
    
    For each myFile in myFileList ' loop through the files
        File.Copy(sOldFolder & myFile.Name, sNewFolder & myFile.Name)
    Next
    %>
    

    Hope this helps,

    Eoin


  • Closed Accounts Posts: 34 jackofnotrades


    Hey thanks that helped alot
    got it working with this
    Dim myArr() As String = Directory.GetFiles(sourceDir)


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    excellent, that's even quicker than the way you have to do it in old ASP I think...


Advertisement