Solved

cannot get txt file and move them to new location

Posted on 2006-06-27
20
224 Views
Last Modified: 2010-04-23
   Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click

        Dim SourcePath As String = ("SourcePath")
        Dim DestPath As String = ("DestinationPath")  '<-- Get Destination path also from config
        '        Dim Fls() As String = Directory.GetFiles(SourcePath, ("*.txt"))  '<-- search for only TXT files
        Dim Fls() As String = Directory.GetFiles("SourcePath")
        For Each Fl As String In Fls
            If File.GetCreationTime(Fl) < Today.AddDays(-10) And (Fl.EndsWith(".txt")) Then
                File.Move(Fl, DestPath & Fl.Substring(Fl.LastIndexOf("\"))) '<-- and move to destination folder
            End If
        Next
    End Sub

appconfig file--
      <appSettings>
            <add key="SourcePath" value="C:\test\files" />
            <add key="DestinationPath" value="C:\test\archive" />
      </appSettings>
0
Comment
Question by:Padre_Corleone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 9
20 Comments
 
LVL 11

Expert Comment

by:MacNuttin
ID: 16994107
Directory.GetFiles("SourcePath")
Does this return a string or an array of strings?
0
 
LVL 7

Author Comment

by:Padre_Corleone
ID: 16994124
Error      1      Value of type '1-dimensional array of String' cannot be converted to 'String'.      C:\Documents and Settings\a\My Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\Form1.vb      11      36      WindowsApplication1

it doesn't work I am using .net 2005
any other suggestions?

0
 
LVL 11

Expert Comment

by:MacNuttin
ID: 16994326
Just as I thought this part is wrong ...
       Dim Fls() As String = Directory.GetFiles("SourcePath")
        For Each Fl As String In Fls

don't have a copy of VS available right now to debug but You need to dim fls as array or dataset or whatever Directory.GetFiles("SourcePath") is. Then write For Each Fl As String In Fls appropriately
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Author Comment

by:Padre_Corleone
ID: 16994350
but i believe that is what i have in my code above right?
0
 
LVL 11

Expert Comment

by:MacNuttin
ID: 16994389
Try:

 Dim Fls() = Directory.GetFiles("SourcePath")
0
 
LVL 11

Expert Comment

by:MacNuttin
ID: 16994468
Go here:
http://www.aspdot.net/aspnet/filedirhandling.aspx

 string[]files =  Directory.GetFiles(path);

Also found this at: http://dotnetjunkies.com/WebLog/dinakar/articles/16284.aspx

Private Sub ShowFiles(path as string)

Dim d() As String

d = System.IO.Directory.GetFiles(path)

Dim en As System.Collections.IEnumerator

en = d.GetEnumerator

While en.MoveNext

MsgBox(CStr(en.Current))

End While

End Sub
0
 
LVL 7

Author Comment

by:Padre_Corleone
ID: 16994507
ok now it works but i get this green underline on my AppSettings

Warning      1      'Public Shared ReadOnly Property AppSettings() As System.Collections.Specialized.NameValueCollection' is obsolete: 'This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings'      E:\etelenext\Clarient\WindowsApplication2\Form1.vb      66      36      WindowsApplication2


'''my code'''
         'Declare values
        Dim SourcePath As String = AppSettings("SourcePath") ''' green underline
        Dim DestPath As String
        'ok now it works just fine but when I use the AppSettings
        DestPath = AppSettings("DestinationPath") & Today.Day.ToString & "_" & Today.Month.ToString & "_" & Today.Year
        If Not Directory.Exists(DestPath) Then Directory.CreateDirectory(DestPath)

        'Dim DestPath As String = AppSettings("DestinationPath")  '<-- Get Destination path also from config
        Dim Fls() As String = Directory.GetFiles(SourcePath, "*.txt")  '<-- search for only TXT files
        For Each Fl As String In Fls
            If File.GetCreationTime(Fl) > Today.AddDays(-10) Then '
                File.Move(Fl, DestPath & Fl.Substring(Fl.LastIndexOf("\"))) '<-- and move to destination folder
            End If
        Next
    End Sub
0
 
LVL 11

Expert Comment

by:MacNuttin
ID: 16994605
0
 
LVL 7

Author Comment

by:Padre_Corleone
ID: 16994725
''how would I implement this in my code example?
0
 
LVL 11

Expert Comment

by:MacNuttin
ID: 16994790
If you can try to change
Dim SourcePath As String = AppSettings("SourcePath") ''' green underline
To
Dim SourcePath As NameValueCollection = ConfigurationSettings.AppSettings("SourcePath")
0
 
LVL 7

Author Comment

by:Padre_Corleone
ID: 16994831
namevaluecollection not defined erros
0
 
LVL 11

Expert Comment

by:MacNuttin
ID: 16994850
Sorry I meant To
Dim SourcePath As NameValueCollection = ConfigurationManager.AppSettings("SourcePath")
0
 
LVL 11

Expert Comment

by:MacNuttin
ID: 16994904
maybe
Imports System
Imports System.Collections
Imports System.Collections.Specialized


Dim SourcePath As New NamevalueCollection()
SourcePath = ConfigurationManager.AppSetting("SourcePath")
0
 
LVL 7

Author Comment

by:Padre_Corleone
ID: 16994961
yes that took care of the message but i still get a proble running this or should this be in my button event?


 Public Shared ReadOnly Property AppSettings() As NameValueCollection
        Get
            Dim SourcePath As NameValueCollection
            SourcePath = ConfigurationManager.AppSettings("SourcePath")

            Dim DestPath As NameValueCollection

            DestPath = ConfigurationManager.AppSettings("DestPath")

        End Get
    End Property
0
 
LVL 7

Author Comment

by:Padre_Corleone
ID: 17002713
any other suggestions to get this working?
0
 
LVL 11

Expert Comment

by:MacNuttin
ID: 17002808
Tonight I'll install VS.NET2005 and try to solve
0
 
LVL 7

Author Comment

by:Padre_Corleone
ID: 17015568
ok i found the solution.  What I need to do is add to my project a reference the system.configuration from the .net tab.  this takes care of the problem.
0
 
LVL 11

Accepted Solution

by:
MacNuttin earned 500 total points
ID: 17038912
What I didn't help you with this? If not for my comments you'd still be using AppSettings.

Imports System
Imports System.Collections
Imports System.Collections.Specialized


Dim SourcePath As New NamevalueCollection()
SourcePath = ConfigurationManager.AppSetting("SourcePath")
0
 
LVL 7

Author Comment

by:Padre_Corleone
ID: 17038971
I apologize MacNuttin you are correct i don't know what i was thinking with this, I believe the reason why I though otherwise was because I kept getting a issue with reference missing and when i added the reference I work.

Thanks for pointing that out for me and much thanks for your help!

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

751 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