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

  • Thread starter Thread starter pamelafluente
  • Start date Start date
P

pamelafluente

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
 
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
 
Back
Top