Solved

If  ...Filename  ...Then

Posted on 2004-04-02
7
294 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

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.

Question has a verified solution.

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

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…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now