-
Jan 21st, 2017, 05:17 AM
#1
Thread Starter
New Member
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 code
-
Jan 21st, 2017, 07:24 AM
#2
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
-
Jan 21st, 2017, 07:52 AM
#3
Thread Starter
New Member
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
-
Jan 23rd, 2017, 11:13 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|