Solved

If  ...Filename  ...Then

Posted on 2004-04-02
7
295 Views
Last Modified: 2011-09-20
Hi,

How can I send a file to a 'folderA' if its file name is 'file1', otherwise I send it to 'folderB' if its name is 'file2' ?

Thanks for your help
0
Comment
Question by:chspit
7 Comments
 
LVL 14

Expert Comment

by:ptakja
ID: 10744151
Could you be more specific?  How do determine the filename?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10744486
ASP.NET or Windows Form?

Bob
0
 

Author Comment

by:chspit
ID: 10744633
i have a FileSystemWatcher that watches a folder. If a file arrives at this specific folder i want the FileSystemWatcher to react by sending the arrived file to 'FolderA' if the file name is 'file1', or send the file to 'FolderB' if file name is 'file2', otherwise the file is deleted.

0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 15

Accepted Solution

by:
Timbo87 earned 125 total points
ID: 10744644
You could do something like this:

Imports System.IO

Dim fileName As String = "c:\file1.txt"
'Dim fileName As String = "c:\file2.txt"

If fileName = "c:\file1.txt" Then
  File.Move(fileName, "c:\folderA\file1.txt")
Else
  File.Move(fileName, "c:\folderB\file1.txt")
End If

You can comment the first fileName and uncomment the second fileName if you want to test it. These files and folders need to exist or the program will throw an exception.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10744659
Dog pile on the easy question!!!!! :)

Bob
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10744661
Something simple like this might help:

   Public Sub TransferFile(ByVal strFileName As String)

      Const FolderA As String = "Folder A"
      Const FolderB As String = "Folder B"

      If strFileName = "file1" Then
         System.IO.File.Copy(strFileName, FolderA)
      ElseIf strFileName = "file2" Then
         System.IO.File.Copy(strFileName, FolderB)
      Else
         System.IO.File.Delete(strFileName)
      End If

   End Sub

Bob
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10744738
Slip sliding away.........

Bob
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question