Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

If  ...Filename  ...Then

Posted on 2004-04-02
7
Medium Priority
?
303 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
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
LVL 15

Accepted Solution

by:
Timbo87 earned 500 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

916 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