Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / January 2006

Tip: Looking for answers? Try searching our database.

Moving files from a folder to another (Newbie-please help)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pamelafluente@libero.it - 06 Jan 2006 02:43 GMT
I have a folder, say C:\ORIGIN, and another folder, say C:\DESTINATION.

I would like that any file which appears on C:\ORIGIN after a given
date, for instance after 07/12/2006, wil be moved immediately (or
within a few seconds) in into C:\DESTINATION.

Would anybody so kind as to show me how to implement this (possibly in
VB.NET,  but any other language will also be fine) ?

Thank YOU very much in advance.

-Pam
Greg Burns - 06 Jan 2006 03:13 GMT
Don't have a sample to give you, but sounds like a job for the
FileSystemWatcher Class

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fsystemiofilesystemwatcherclasstopic.asp


Greg

> I have a folder, say C:\ORIGIN, and another folder, say C:\DESTINATION.
>
[quoted text clipped - 8 lines]
>
> -Pam
pamelafluente@libero.it - 06 Jan 2006 17:45 GMT
Thank you Greg. That worked.

In case it may be useful here is my source code.
I am assuming 1 Form with: 2 TextBoxes, 2 Buttons, 1 RichTextBox, 1
CheckBox
(and a few labels or whatever...).

Suggestions are welcome. If anyone asks for it, I will email the
source.

Imports System.IO

Public Class Form1
   Inherits System.Windows.Forms.Form

'#Region " Windows Form Designer generated code "
'#End Region

   'Private SourceFolder As String
   Private DestinationFolder As String

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

       AddHandler Me.FileSystemWatcher1.Created, AddressOf
MoveNewlyCreatedFile
       Me.FileSystemWatcher1.EnableRaisingEvents = True
   End Sub

   Sub MoveNewlyCreatedFile(ByVal sender As System.Object, ByVal e As
System.io.FileSystemEventArgs)

       Me.DestinationFolder = Me.TextBoxDestDir.Text

       File.Move(e.FullPath, Me.DestinationFolder & "\" & e.Name)

       Me.RichTextBox1.AppendText(e.FullPath & " --> " &
Me.DestinationFolder & "\" & e.Name & vbCrLf)
   End Sub

   Private Sub ButtonPickSourceDir_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ButtonPickSourceDir.Click
       Dim FolderBrowserDialog As New FolderBrowserDialog
       If FolderBrowserDialog.ShowDialog() = DialogResult.OK Then
           Me.TextBoxSourceDir.Text = FolderBrowserDialog.SelectedPath
       End If
       FolderBrowserDialog.Dispose()
   End Sub

   Private Sub ButtonPickDestDir_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ButtonPickDestDir.Click
       Dim FolderBrowserDialog As New FolderBrowserDialog
       If FolderBrowserDialog.ShowDialog() = DialogResult.OK Then
           Me.TextBoxDestDir.Text = FolderBrowserDialog.SelectedPath
       End If
       FolderBrowserDialog.Dispose()
   End Sub

   Private Sub TextBoxSourceDir_TextChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
TextBoxSourceDir.TextChanged
       Me.FileSystemWatcher1.EnableRaisingEvents = False
       Me.CheckBox1.Checked = False
   End Sub

   Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged

       If Me.TextBoxDestDir.Text.Trim = "" OrElse
Me.TextBoxSourceDir.Text.Trim = "" Then
           MsgBox("Pick both folders", MsgBoxStyle.Information)
           Exit Sub
       End If

       Me.FileSystemWatcher1.Path = Me.TextBoxSourceDir.Text
       Me.FileSystemWatcher1.EnableRaisingEvents =
Me.CheckBox1.Checked
   End Sub

   Private Sub TextBoxDestDir_TextChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
TextBoxDestDir.TextChanged
       Me.FileSystemWatcher1.EnableRaisingEvents = False
       Me.CheckBox1.Checked = False
   End Sub

End Class

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.