?
Solved

Process file rename based on multiple textboxes

Posted on 2008-01-30
19
Medium Priority
?
814 Views
Last Modified: 2011-10-19
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
0
Comment
Question by:Judson Hall
  • 10
  • 9
19 Comments
 
LVL 48

Expert Comment

by:Jorge Paulino
ID: 20781817
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
 

Author Comment

by:Judson Hall
ID: 20781857
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
 
LVL 48

Expert Comment

by:Jorge Paulino
ID: 20781899
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:Judson Hall
ID: 20787209
Any suggestions on how to call the data as (column, row) and step through rows to rename the individual files?
0
 
LVL 48

Expert Comment

by:Jorge Paulino
ID: 20787537
You can do this:

For Each row As DataGridViewRow In DataGridView1.Rows
            MessageBox.Show(row.Cells("ColumnNameOrIndex").Value)
Next
0
 
LVL 48

Expert Comment

by:Jorge Paulino
ID: 20787783
To call just one you can use DataGridView1(row,column).Value
0
 

Author Comment

by:Judson Hall
ID: 20788517
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
 
LVL 48

Expert Comment

by:Jorge Paulino
ID: 20789463
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
 

Author Comment

by:Judson Hall
ID: 20789952
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
 
LVL 48

Expert Comment

by:Jorge Paulino
ID: 20790302
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
 

Author Comment

by:Judson Hall
ID: 20790452
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
 
LVL 48

Expert Comment

by:Jorge Paulino
ID: 20790737
Can you upload you project or do you want a sample ?
0
 

Author Comment

by:Judson Hall
ID: 20791919
It's uploaded ....
0
 
LVL 48

Expert Comment

by:Jorge Paulino
ID: 20791974
I could not found for this question. Can you chek it again ?
0
 
LVL 48

Accepted Solution

by:
Jorge Paulino earned 2000 total points
ID: 20797237
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
 

Author Comment

by:Judson Hall
ID: 20800600
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
 

Author Comment

by:Judson Hall
ID: 20801045
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
 

Author Closing Comment

by:Judson Hall
ID: 31426512
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

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
If you are looking for an automated solution for backup single or multiple Office 365 user mailboxes to Outlook data file, then you can use Kernel Office 365 Backup & Restore tool. Go through the video to check out the steps to backup single or mult…

599 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question