Solved

cannot get txt file and move them to new location

Posted on 2006-06-27
20
219 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
  • 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
 
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
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).

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

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