dcsimg
Results 1 to 5 of 5

Thread: Renaming files listed at listbox_Code for "Rename" buttom?

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2019
    Posts
    2

    Renaming files listed at listbox_Code for "Rename" buttom?

    I'm trying to create a little program thats introduce some prefixes into the name of the files that found at a folder.

    The names of files are listed at a Listbox1 and the prefixes are choosed at a several Comboboxes.

    This names of the Listbox1 with the choosed prefixes of the Comboboxes are moved to a Listbox2 pressing a buttom ">>>".
    When all of new names are ready at this Listbox2 will be press a buttom "Rename" and the names of files at the folder will be changed according fixed at the Listbox2.


    All of the Userform is already programmed. I have just problems to build the code for the buttom "Rename".
    In others Words, taking the stipulate names of the Listbox2 and changing the names at the respective files showed before at the Listbox1.

    How i can read the new names of files from a Listbox and introduce to the respective name of file?

    1000 Thanks for your feedbacks in advance!

    Name:  Userform.jpg
Views: 111
Size:  18.6 KB

    Code:
    Code:
    Private Sub cmdMoveSelLeft_Click()
    
        'Variable Declaration
        Dim iCnt As Integer
    
        'Move Selected Items from Listbox1 to Listbox2
        For iCnt = 0 To Me.ListNewFiles.ListCount - 1
            If Me.ListNewFiles.Selected(iCnt) = True Then
                Dim changedName As String
                changedName = Me.ComboBoxKategorie.Value + "_" + Me.ComboBoxTyp.Value + "_" + Me.ListNewFiles.List(iCnt)
                Me.ListChangedFiles.AddItem changedName
            End If
        Next
    
        For iCnt = Me.ListNewFiles.ListCount - 1 To 0 Step -1
            If Me.ListNewFiles.Selected(iCnt) = True Then
                Me.ListNewFiles.RemoveItem iCnt
            End If
        Next
        ComboBoxKategorie = ""
        ComboBoxTyp = ""
        TextBoxEXX = ""
        TextBoxUX = ""
        TextBoxTrakt = ""
        TextBoxGebaude = ""
        TextBoxSpecific = ""
        
        
    End Sub
    ---
    
    Private Sub cmdRename_Click()
    
    Dim Msg, Style, Title, Help, Ctxt, Response, MyString
    Msg = "Möchten Sie fortfahern?"
    Style = vbYesNo + vbQuestion + vbDefaultButton2
    Title = "Bestätigung"
    Help = "DEMO.HLP"
    Ctxt = 1000
    
    Response = MsgBox(Msg, Style, Title, Help, Ctxt)
    
    If Response = vbYes Then    ' User chose Yes.
    
    ??????
            
            MsgBox "Die Namen sind angepasst" & vbCrLf
            Unload Me
    End If
    
    End Sub
    Last edited by Shaggy Hiker; Aug 15th, 2019 at 07:17 PM. Reason: Introducing CODE tags.

  2. #2
    Fanatic Member
    Join Date
    Feb 2003
    Posts
    721

    Re: Renaming files listed at listbox_Code for "Rename" buttom?

    Quote Originally Posted by WUWcode View Post
    I'm trying to create a little program thats introduce some prefixes into the name of the files that found at a folder.

    The names of files are listed at a Listbox1 and the prefixes are choosed at a several Comboboxes.

    This names of the Listbox1 with the choosed prefixes of the Comboboxes are moved to a Listbox2 pressing a buttom ">>>".
    When all of new names are ready at this Listbox2 will be press a buttom "Rename" and the names of files at the folder will be changed according fixed at the Listbox2.


    All of the Userform is already programmed. I have just problems to build the code for the buttom "Rename".
    In others Words, taking the stipulate names of the Listbox2 and changing the names at the respective files showed before at the Listbox1.

    How i can read the new names of files from a Listbox and introduce to the respective name of file?

    1000 Thanks for your feedbacks in advance!

    Name:  Userform.jpg
Views: 111
Size:  18.6 KB
    Hi,

    Could you post your project's files in an attachment? That will make it easier to see what you are doing and to help you.

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2019
    Posts
    2

    Re: Renaming files listed at listbox_Code for "Rename" buttom?

    Code:
    Code:
    Private Sub cmdMoveSelLeft_Click()
    
        'Variable Declaration
        Dim iCnt As Integer
    
        'Move Selected Items from Listbox1 to Listbox2
        For iCnt = 0 To Me.ListNewFiles.ListCount - 1
            If Me.ListNewFiles.Selected(iCnt) = True Then
                Dim changedName As String
                changedName = Me.ComboBoxKategorie.Value + "_" + Me.ComboBoxTyp.Value + "_" + Me.ListNewFiles.List(iCnt)
                Me.ListChangedFiles.AddItem changedName
            End If
        Next
    
        For iCnt = Me.ListNewFiles.ListCount - 1 To 0 Step -1
            If Me.ListNewFiles.Selected(iCnt) = True Then
                Me.ListNewFiles.RemoveItem iCnt
            End If
        Next
        ComboBoxKategorie = ""
        ComboBoxTyp = ""
        TextBoxEXX = ""
        TextBoxUX = ""
        TextBoxTrakt = ""
        TextBoxGebaude = ""
        TextBoxSpecific = ""
        
        
    End Sub
    -----
    
    Private Sub cmdRename_Click()
    
    Dim Msg, Style, Title, Help, Ctxt, Response, MyString
    Msg = "Möchten Sie fortfahern?"
    Style = vbYesNo + vbQuestion + vbDefaultButton2
    Title = "Bestätigung"
    Help = "DEMO.HLP"
    Ctxt = 1000
    
    Response = MsgBox(Msg, Style, Title, Help, Ctxt)
    
    If Response = vbYes Then    ' User chose Yes.
    
    ??????????
            
            MsgBox "Die Namen sind angepasst" & vbCrLf
            Unload Me
    End If
    Last edited by Shaggy Hiker; Aug 15th, 2019 at 07:18 PM. Reason: Added CODE tags.

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,054

    Re: Renaming files listed at listbox_Code for "Rename" buttom?

    An 'attachment' means you zip up your project (without any .exe files) and add it to your thread (Need to us the 'Go Advanced' button to add attachments).

  5. #5
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,054

    Re: Renaming files listed at listbox_Code for "Rename" buttom?

    Here is a sample file (using SOME of your code) to do what I THINK you want to do.....
    Attached Files Attached Files

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width