Solved

If  ...Filename  ...Then

Posted on 2004-04-02
7
293 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

15 Experts available now in Live!

Get 1:1 Help Now