borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2011 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Next Topic (Plz. Help) New Topic New Poll Post Reply
AndreaVB Forum : VB.Net : Plz help
Poster Message
lonelyluminary
Level: Protégé

Registered: 07-08-2011
Posts: 8

icon Plz help

I have tried to change the script a bit, but it just moves items from one listbox to another, but I wanted to move files, which listbox is showing.  

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim i As Integer
        i = ListBox2.SelectedItems.Count - 1
        Do While i >= 0

            ListBox1.Items.Add(ListBox2.SelectedItems.Item(i))

            ListBox2.Items.Remove(ListBox2.SelectedItems.Item(i))

            i = i - 1

        Loop

13-08-2011 at 05:10 PM
View Profile Send Email to User Show All Posts | Quote Reply
GeoffS
Level: VB Lord


Registered: 29-09-2004
Posts: 610
icon Re: Plz help

Populating a listbox with list items, and moving files on the file system of your computer are 2 entirely different things.
You need to use the FileCopy method of the FileSystem Class in .NET - this takes 2 arguements, the name of the file that you want to move (including the full path to the file) and the name and path of the newly created file.
So I presume your listbox contains that information, so pass each file to move into a variable, copy it, then if you want the origional file removed use the Kill Method of the FileSystem Class.

Dim strSourceFile As String
Dim strDestinationFile As String

strSourceFile = ListBox2.SelectedItems.Item(i).ToString
strDestinationFile = "C:\\My Documents\\NewFileName.txt"
FileCopy(strSourceFile, strDestinationFile)
Kill(strSourceFile)




____________________________
multi-tasking - the ability to hang more than one app. at the same time.

26-08-2011 at 01:40 PM
View Profile Send Email to User Show All Posts | Quote Reply
lonelyluminary
Level: Protégé

Registered: 07-08-2011
Posts: 8
icon Re: Plz help

First of all Thanks for the reply.  I could not get any help while I was writing the code, but later I tried this, which is working pretty well.

Try
            ' identify items that have been selected in the listbox
            'and moves them from one folder to another
            Dim intCount As Integer 'count number of items in the listbox
            Dim FileToMove As String
            For intCount = 0 To Me.ListBox1.SelectedItems.Count.ToString() - 1
                If Not Me.ListBox1.SelectedItems(intCount) Is Nothing Then
                    FileToMove = Me.ListBox1.SelectedItems(intCount).ToString()
                    'Move files one by one from source folder to destination folder
                    Dim fso
                    Dim file As String, sfol As String, dfol As String
                    file = FileToMove
                    sfol = "c:\" & Format(DateTimePicker1.Value, ("MM-dd-yyyy")) & "\" 'source folder path (left side)
                    dfol = "c:\" & Format(ComboBox1.Text) & "\"    'source folder path (right side)
                    fso = CreateObject("Scripting.FileSystemObject")
                    'Check if file exists
                    If Not fso.FileExists(sfol & file) And Not fso.FileExists(dfol & file) Then
                        MsgBox(file & " does not exist in the source directory!", vbExclamation, "File Missing in source file")
                        'If exist replace
                    ElseIf fso.FileExists(sfol & file) And fso.FileExists(dfol & file) Then
                        MsgBox(file & " already exists in the destination folder", vbExclamation, "File Duplication")
                    ElseIf Not fso.FileExists(dfol & file) Then
                        fso.MoveFile((sfol & file), dfol)
                        MsgBox(file & " has now been moved!", vbExclamation, "Requested action complete")

                    Else
                        MsgBox(file & " has already been moved!", vbExclamation, "File Exists in destination folder")
                    End If
                    If Err.Number = 53 Then MsgBox("File not found")
                End If
            Next
            'update listboxes
            Dim i, f As Integer
            i = ListBox1.SelectedItems.Count - 1
            Do While i >= 0

                ListBox2.Items.Add(ListBox1.SelectedItems.Item(i))

                ListBox1.Items.Remove(ListBox1.SelectedItems.Item(i))

                i = i - 1

            Loop
            f = ListBox2.SelectedItems.Count - 1
            Do While f >= 0

                ListBox1.Items.Add(ListBox2.SelectedItems.Item(i))

                ListBox2.Items.Remove(ListBox2.SelectedItems.Item(i))

                f = f - 1

            Loop
        Catch ex As Exception
            WriteLog("Error :" & Date.Now.ToString & " " & ex.Message)
            MsgBox("Nothing to Add! Please click 'Remove' Button")
        End Try

29-08-2011 at 02:54 PM
View Profile Send Email to User Show All Posts | Quote Reply
lonelyluminary
Level: Protégé

Registered: 07-08-2011
Posts: 8
icon Re: Plz help

Hi GeoffS,  Now I have problem with another code.  I want to get the play time of media files selected in the listbox.  Is it possible to get total play time without opening the media file.


Waiting for reply anxiously.  I greatly appreciate any help.

29-08-2011 at 02:58 PM
View Profile Send Email to User Show All Posts | Quote Reply
GeoffS
Level: VB Lord


Registered: 29-09-2004
Posts: 610
icon Re: Plz help

That's a bit specialist - the file attributes available through dotNet will not give you the info you need.
You might find the answer on a specialist devolopers forum for media players - try:-
http://forums.winamp.com/


____________________________
multi-tasking - the ability to hang more than one app. at the same time.

30-08-2011 at 03:23 PM
View Profile Send Email to User Show All Posts | Quote Reply
lonelyluminary
Level: Protégé

Registered: 07-08-2011
Posts: 8
icon Re: Plz help

Thanks a ton.

One more confusion. first see the code
Dim selfile As String
        For Me.intCount = 0 To Me.ListBox1.SelectedItems.Count.ToString() - 1
            If Not Me.ListBox1.SelectedItems(intCount) Is Nothing Then
                selfile = Me.ListBox1.SelectedItems(intCount).ToString()
                Dim filesize As Long = selfile.Length
                TextBox2.Text = filesize
            End If
        Next
Now it gives me the last selected file's length, which is understood.  I want to see all selected files length.  Appreciate your help GeoffS.

30-08-2011 at 03:59 PM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 517
icon Re: Plz help

Sum all file size


Dim selfile As String
Dim filesize As Long
        filesize = 0
        For Me.intCount = 0 To Me.ListBox1.SelectedItems.Count.ToString() - 1
            If Not Me.ListBox1.SelectedItems(intCount) Is Nothing Then
                selfile = Me.ListBox1.SelectedItems(intCount).ToString()
                filesize = filesize + selfile.Length
            End If
        Next
        TextBox2.Text = filesize


____________________________
AndreaVB

31-08-2011 at 06:30 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
lonelyluminary
Level: Protégé

Registered: 07-08-2011
Posts: 8
icon Re: Plz help

Thanks a ton.

01-09-2011 at 02:58 PM
View Profile Send Email to User Show All Posts | Quote Reply
lonelyluminary
Level: Protégé

Registered: 07-08-2011
Posts: 8
icon Re: Plz help

file length property is not giving actual size of a file.     

02-09-2011 at 07:07 AM
View Profile Send Email to User Show All Posts | Quote Reply
GeoffS
Level: VB Lord


Registered: 29-09-2004
Posts: 610
icon Re: Plz help

No - you are reading  the length of the string that represents the filename and path.
Use FileSystem Class again - FileSystem.FileLen(path) Returns filesize in Bytes as a Long

filesize = filesize + FileLen(selfile)



____________________________
multi-tasking - the ability to hang more than one app. at the same time.

02-09-2011 at 02:29 PM
View Profile Send Email to User Show All Posts | Quote Reply
lonelyluminary
Level: Protégé

Registered: 07-08-2011
Posts: 8
icon Re: Plz help

Thanks

05-09-2011 at 03:17 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB.Net : Plz help
Next Topic (Plz. Help) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2011 Andrea Tincaniborder