Process file rename based on multiple textboxes

I am attempting to automate the rename procedure on files in a userdefined folder from name.mov to a specifc format (i.e rename fie1.mov to textbox1.text_textbox2.text_textbox3.text.mov)
I have the code working to process one instance at a time. What is the best way to handle up to 10 instances at one time OR possibly an excel spreadsheet with many instances.
It was suggested to use a datagridview or dataset however I'm not familiar with these processes.
I'm attaching a gif of my desired user form and the code that I have so far.

Thanks for the assistance


Imports System.IO
 
Public Class Form1
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 
        If FolderBrowserDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
            Label1.Text = FolderBrowserDialog.SelectedPath
 
        End If
 
    End Sub
 
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
 
        Dim filenamepath As String = Label1.Text ' (you can get this using System.IO namespace)
        Dim oldfilename As String = filenamepath & "\" & Orig1.Text
        Dim newfilename As String = filenamepath & "\" & HouseNum1.Text & "_" & ISCI1.Text & "_" & Length1.Text & "_" & Title1.Text & ".mov"
 
        Microsoft.VisualBasic.FileSystem.Rename(oldfilename, newfilename)
 
    End Sub
 
End Class

Open in new window

avidconvert.gif
Judson HallSystems AdminAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jorge PaulinoIT Pro/DeveloperCommented:
Hi again,

I think that the datagridview it's the best control for you. You can add 4 column + 1 for button. With this button you will display the FolderBrowserDialog and populate the file name. You just have to leave two columns for the user to write the names and set the others as readonly.

When you press save you just have to loop for each rows and rename the file.

After you start you will see that it's easy to achieve.
0
Judson HallSystems AdminAuthor Commented:
I'll work on this now .... I'll post again in the AM after I work on it some. I've never worked with datagridview before. This should be a nice learning experience.
0
Jorge PaulinoIT Pro/DeveloperCommented:
It's very easy and a good control. I like listview also but when you need that the user fills data this one it's better.

Do some test and post when you already have something (code, problems, etc)

Everything is a nice learning experience in here :-)
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Judson HallSystems AdminAuthor Commented:
Any suggestions on how to call the data as (column, row) and step through rows to rename the individual files?
0
Jorge PaulinoIT Pro/DeveloperCommented:
You can do this:

For Each row As DataGridViewRow In DataGridView1.Rows
            MessageBox.Show(row.Cells("ColumnNameOrIndex").Value)
Next
0
Jorge PaulinoIT Pro/DeveloperCommented:
To call just one you can use DataGridView1(row,column).Value
0
Judson HallSystems AdminAuthor Commented:
10 -4 ...

I can't figure out how to Dim the first line .... attached is my attempt that failed miserably.
As you can see the row, Cells presents an error. i probably not even useing the correct syntax (of course I can't find it anywhere either)

If you could help me on this part I'm sure I can re-write your example to rename the files (hopefully!)

Dim oldfilename As String = filenamepath & "\" & DataGridView1(row.Cells("column1").Value)
Dim newfilename As String = filenamepath & "\" & DataGridView1(row.Cells("column2").Value) & "_" & DataGridView1(row.Cells("column3").Value) & "_" & DataGridView1(row.Cells("column4").Value) & "_" & DataGridView1(row.Cells("column5").Value) & ".mov"

Open in new window

0
Jorge PaulinoIT Pro/DeveloperCommented:
If you use the above code for the loop, then you down need it to use DataGridView1. Remove that reference and do try this way:

For Each row As DataGridViewRow In DataGridView1.Rows
 If row.Cells("column1").Value <> "" Then
   Dim oldfilename As String = filenamepath & "\" & row.Cells("column1").Value
  Dim newfilename As String = filenamepath & "\" & row.Cells("column2").Value & "_" & row.Cells("column3").Value & "_" & row.Cells("column4").Value & "_" & row.Cells("column5").Value & ".mov"
End If
Next
0
Judson HallSystems AdminAuthor Commented:
I am soooo missing something here .....

What I think should be going on is ....
1. I Dim my variables
2. I count through row 1
3. I process row 1
4. I count through row 2
5. I process row 2
6. etc etc

I don't know how to use this code to rename the files in my dir1.text directory.

Do you have a sample of a similar use that I could use as a reference?

Here is ALL my code so far .....
Imports System.IO
 
Public Class Form1
 
    Private Sub SrcDir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SrcDir.Click
 
        If FolderBrowserDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
            Dir1.Text = FolderBrowserDialog.SelectedPath
 
        End If
 
    End Sub
 
    Private Sub FlPrcs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FlPrcs.Click
        Dim filenamepath As String = Dir1.Text
 
        For Each row As DataGridViewRow In DataGridView1.Rows
            If row.Cells("column1").Value <> "" Then
                Dim oldfilename As String = filenamepath & "\" & row.Cells("column1").Value
                Dim newfilename As String = filenamepath & "\" & row.Cells("column2").Value & "_" & row.Cells("column3").Value & "_" & row.Cells("column4").Value & "_" & row.Cells("column5").Value & ".mov"
            End If
        Next
 
    End Sub
 
End Class

Open in new window

0
Jorge PaulinoIT Pro/DeveloperCommented:
But it's missing the rename command: Microsoft.VisualBasic.FileSystem.Rename(oldfilename, newfilename)

For Each row As DataGridViewRow In DataGridView1.Rows
            If row.Cells("column1").Value <> "" Then
                Dim oldfilename As String = filenamepath & "\" & row.Cells("column1").Value
                Dim newfilename As String = filenamepath & "\" & row.Cells("column2").Value & "_" & row.Cells("column3").Value & "_" & row.Cells("column4").Value & "_" & row.Cells("column5").Value & ".mov"
                 
                Microsoft.VisualBasic.FileSystem.Rename(oldfilename, newfilename)

            End If
        Next

Also how do you load the files in the datagridview ? If you want you can upload a sample in www.ee-stuff.com and I will check it.
0
Judson HallSystems AdminAuthor Commented:
Right now i'm manually entering data.

I'll give you a basic rundown of the issue I'm trying to resolve.
We have some very non-tech people that create video files. They name the files something very simple like "file1.mov". The files are uploaded to a program (Telestream) that converts the files into MPEG4 files. The catch is, the Ops people then have to manually enter the metadata that indicates what the file is, when it runs, how long it is and a "familiar" file name. If the file was named in a specific format it would resolve this issue.

My attempt at resolving this tedious process is to create a program that easily allow the editor to enter their file name and the associated metadata click a button, and the program renames the files automatically in the correct format.

Most files are done in small batches, hence the desired single form design, but I will enventually need to creat ea button that allows the editor to import an excel file. Datagridview will definitly make this process easier than an array of textboxes.

I am not a programmer (I'm actually a systems engineer) but I do know a little VB Scripting that i use in day to day networking processes.

I really do appriciate the assistance, your help has been very invaluable.
0
Jorge PaulinoIT Pro/DeveloperCommented:
Can you upload you project or do you want a sample ?
0
Judson HallSystems AdminAuthor Commented:
It's uploaded ....
0
Jorge PaulinoIT Pro/DeveloperCommented:
I could not found for this question. Can you chek it again ?
0
Judson HallSystems AdminAuthor Commented:
0
Jorge PaulinoIT Pro/DeveloperCommented:
Hi judsonhh,

Try to use this code to add the files to the datagridview

Private Sub SrcDir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SrcDir.Click

        If FolderBrowserDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
            Dir1.Text = FolderBrowserDialog.SelectedPath
            Dim myFile() As String = IO.Directory.GetFiles(Dir1.Text, "*.mov")

            For x As Integer = 0 To myFile.Length - 1
                Dim fi As New FileInfo(myFile(x))
                DataGridView1.Rows.Add(myFile(x), "", "", fi.Length.ToString & " bts")
            Next

        End If

    End Sub


One more thing: In the example you have show me you are trying to copy the files, not rename. If you want to do that you can do:

File.Copy(source, destination)

For Each row As DataGridViewRow In DataGridView1.Rows
            If row.Cells("column1").Value <> "" Then
                Dim oldfilename As String = srcnamepath & "\" & row.Cells("column1").Value
                Dim newfilename As String = destnamepath & "\" & row.Cells("column2").Value & "_" & row.Cells("column3").Value & "_" & row.Cells("column4").Value & "_" & row.Cells("column5").Value & ".mov"
                File.Copy(oldfilename, newfilename)
            End If
        Next
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Judson HallSystems AdminAuthor Commented:
Is it possible to use Either method to populate the dataviewgrid? I'll upload another zip with an idea.

https://filedb.experts-exchange.com/incoming/ee-stuff/6737-Avid-File-Renamer.zip 

My Filewatcher is also not working on the first process, if the process is run on another file rename it does work though.

I also noticed that with a "move" it is not removing the original file.
0
Judson HallSystems AdminAuthor Commented:
The scope of this thread is "evolving" I'm going to close it and open another thread.  The initial problem has been resolved and more issues have presented.
0
Judson HallSystems AdminAuthor Commented:
I'm opening another thread .... you have provided plenty of help and I feel that 500 points is clearly not enough ... I'll repack the project and post the thread url .
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.