Results 1 to 4 of 4

Thread: Simple Move Programme

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2016
    Posts
    2

    Simple Move Programme

    Hi

    I cannot seem to find the find the problem in the code I tried.

    Basically it is 2 buttons that move files between 3 folders.
    When button one is clicked it should take the oldest 3 files in folder 1(based on created date and time)
    and move it to folder 2. Button 2 when clicked should take all files in folder 2 and move it to folder 3.

    I hope someone could point out the mistake
    kind regards

    p.s attached is the codeName:  code.jpg
Views: 220
Size:  26.0 KB

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: Simple Move Programme

    You're new (Welcome btw) ... so you may not realize that the screenshot is useless to us. Because it is a full screen, the forums shrink it down to the point where most of us can't read it. Also we can't copy the code to try it out, or to make corrections to it.
    Your best bet is to copy the code, click the # button in the toolbar just above the reply box (this will add [code][/code] tags to it, then paste the code BETWEEN the code tags... that will preserve the formatting and give us the code in a nice, readable format.

    Just follow that simple request and you'll find it goes a long way to getting help around here.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2016
    Posts
    2

    Re: Simple Move Programme

    My apologies... I did not check to see if it is readable
    Here is the code

    Code:
    Public Class form1
        Dim path As String = "C:\Users\Ashleigh\Desktop\In" ' all new/Imported files
        Dim path2 As String = "C:\Users\Ashleigh\Desktop\Edit" ' All files to be opened from 3rd Party app(Only 3 files allowed at a time)
        Dim path3 As String = "C:\Users\Ashleigh\Desktop\Out" ' Backup of files
    
        Private Sub button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim files As New List(Of IO.FileInfo)
    
            For Each fi As IO.FileInfo In New IO.DirectoryInfo("C:\Users\Ashleigh\Desktop\In").GetFiles
                If Not (fi.Attributes And IO.FileAttributes.Hidden) = IO.FileAttributes.Hidden Then ' filter out the hidden files like thumbs.db
                    files.Add(fi)
                End If
            Next
    
            files = files.OrderByDescending(Function(x) x.CreationTime).ToList 'sort files from newest to oldest !!!!(Should be from oldest to newest)
            If files.Count > 3 Then files = files.Take(3).ToList 'Only keep the first 3 files if there is more than 3 in folder
    
            For Each file As IO.FileInfo In files 'Move the 3 files selected to new location(path2)
                file.MoveTo(path2)
            Next
    
        End Sub
    
        Private Sub button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            file.MoveTo(path2, path3) ' Move the 3 files from Edit folder to Out folder
        End Sub
    End Class

  4. #4
    Frenzied Member
    Join Date
    Dec 2014
    Location
    VB6 dinosaur land
    Posts
    1,191

    Re: Simple Move Programme

    Code:
    file.MoveTo(path2, path3)
    is not valid since file is not what you think it is there. I'm surprised that would compile. You should turn Option Strict on in your project properties perhaps.

    Using just the Move method would work except that your parameters are paths rather than filenames. You could just copy some of what you've done for button1 though you don't say if you have an error there as well. I didn't test this.

    Code:
        Private Sub button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    
            For Each fi As IO.FileInfo In New IO.DirectoryInfo(path2).GetFiles
                If Not (fi.Attributes And IO.FileAttributes.Hidden) = IO.FileAttributes.Hidden Then ' filter out the hidden files like thumbs.db
                    fi.MoveTo(path3)
                End If
            Next
    
        End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width