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

x
?
Solved

cannot get txt file and move them to new location

Posted on 2006-06-27
20
Medium Priority
?
230 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

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…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Loops Section Overview
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. …

885 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