Results 1 to 10 of 10

Thread: [SOLVED]Move number of files

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    203

    [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.

  2. #2
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: Move number of files

    Read a little about :
    My.Computer.FileSystem. & System.IO.

    http://vbnotebookfor.net/2007/07/25/...-vbnet-part-i/

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    203

    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?

  4. #4
    Addicted Member Dark Anima's Avatar
    Join Date
    Sep 2008
    Posts
    183

    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

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    203

    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

  6. #6
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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 -

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    203

    Re: Move number of files

    Thanks, but I already sorted it out

  8. #8
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Move number of files

    Quote Originally Posted by vixez View Post
    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 -

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    203

    Re: [SOLVED]Move number of files

    Sorry, my bad.
    Fixed

  10. #10
    Member Nicelydone's Avatar
    Join Date
    Nov 2009
    Location
    Arizona
    Posts
    61

    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
  •  



Click Here to Expand Forum to Full Width