Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

cannot get txt file and move them to new location

Posted on 2006-06-27
20
Medium Priority
?
229 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

730 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