|
-
Nov 16th, 2009, 12:04 PM
#1
Thread Starter
Addicted Member
[SOLVED]Move number of files
Hey, I'm kinda stuck on this one.
I'm trying to write a tool to move a number of files to a folder.
Example : I have a folder that contains 6 images.
I then press a button, and for each 2 images it creates a folder (1,2,3,...) and moves the two images in the newly created folder.
So:
001.jpg
002.jpg
003.jpg
004.jpg
005.jpg
006.jpg
This will result in 3 folders
F1: 001.jpg, 002.jpg
F2: 003.jpg, 004.jpg
F3: 005.jpg, 006.jpg
What I tried:
I tried placing all files in the folder in a listbox with the full path, but I can't figure out what to do from here.
The most troublesome part is, how to make it move 2 files at a time, place them in a folder and them move onto the next 2 until the folder is empty.
help?
Last edited by vixez; Nov 17th, 2009 at 01:02 PM.
-
Nov 16th, 2009, 12:32 PM
#2
Re: Move number of files
Read a little about :
My.Computer.FileSystem. & System.IO.
http://vbnotebookfor.net/2007/07/25/...-vbnet-part-i/
-
Nov 16th, 2009, 12:48 PM
#3
Thread Starter
Addicted Member
Re: Move number of files
It's helpful, but the part I'm stuck on is how to select each time 2 files and move those into a new folder.
I can do "For Each file in Listbox1", but then it's only one file, how do I get a number of files?
-
Nov 16th, 2009, 03:11 PM
#4
Addicted Member
Re: Move number of files
Maybe something like this?
Code:
While(i < ListBox.Items.Count - 1)
MoveFile(Files(i), Folders(j))
i +=1
MoveFile(Files(i), Folders(j))
i +=1 : j+=1
End While
-
Nov 17th, 2009, 12:02 PM
#5
Thread Starter
Addicted Member
Re: Move number of files
I altered the way I worked, step by step:
1. Get the path from the user
2. Load all files in listbox1
3. User enters the desired number of files per folder (let's call it XYZ)
4. The user hits the Split button, which works like this
*note : the current folder number is in label1, so it starts with 1
a) If *path*\label1.text exists, then it'll start copying XYZ files.
b) After each file copied, it checks the amount of files in the folder.
If there are XYZ files in the folder, it all +1 to the value of label1
Resulting in label1 have 2 as text
Then it starts over,
does *path*\label1.text (which is now 2) exist?
If not create folder and start copying
else start copying
Again, after each copied file check the amount of files.
and so on until there are no more files left
-
Nov 17th, 2009, 12:20 PM
#6
Re: Move number of files
Supposed you have these variables:
Code:
items() : an array containing the full paths to the files to be moved
filesPerFolder: how many files to move to each folder
destinations(): an array containing the destination folder paths
Try something like this.
Code:
Dim itemMoved As Integer = 0
Dim folderIndex As Integer = 0
Try
For i As Integer = 0 To items.GetUpperBound(0)
If Not IO.Directory.Exists(destinations(folderIndex)) Then
IO.Directory.CreateDirectory(destinations(folderIndex))
End If
System.IO.File.Move(items(i), destinations(folderIndex))
itemMoved += 1
If itemMoved = filesPerFolder Then
itemMoved = 0
folderIndex += 1
If folderIndex > destinations.GetUpperBound(0) Then
Exit For
End If
End If
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Nov 17th, 2009, 12:54 PM
#7
Thread Starter
Addicted Member
Re: Move number of files
Thanks, but I already sorted it out
-
Nov 17th, 2009, 12:58 PM
#8
Re: Move number of files
 Originally Posted by vixez
Thanks, but I already sorted it out 
Shouldn't you mark the thread as resolved then?
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Nov 17th, 2009, 01:03 PM
#9
Thread Starter
Addicted Member
Re: [SOLVED]Move number of files
Sorry, my bad.
Fixed
-
Nov 17th, 2009, 05:01 PM
#10
Member
Re: [SOLVED]Move number of files
Well Dude, Vixez, your killing me man. What was your solution!!? LOL
I need some functionality like this in my project.
NicelyDone: The Visual Studio 2008 Newb 
There are 10 types of people in this world...Those who know binary and those who don't. 
*cough* Asimov *cough*
I used to be a pro at HTML...Wait, nooooo! Epic fail
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
|