File Compare and Move - Same File Name with Different File Extensions
File Compare and Move - Same File Name with Different File Extensions
File Compare and Move - Same File Name with Different File Extensions
File Compare and Move - Same File Name with Different File Extensions
File Compare and Move - Same File Name with Different File Extensions
File Compare and Move - Same File Name with Different File Extensions File Compare and Move - Same File Name with Different File Extensions File Compare and Move - Same File Name with Different File Extensions File Compare and Move - Same File Name with Different File Extensions File Compare and Move - Same File Name with Different File Extensions File Compare and Move - Same File Name with Different File Extensions File Compare and Move - Same File Name with Different File Extensions File Compare and Move - Same File Name with Different File Extensions
File Compare and Move - Same File Name with Different File Extensions File Compare and Move - Same File Name with Different File Extensions
File Compare and Move - Same File Name with Different File Extensions
Go Back  Xtreme Visual Basic Talk > > > File Compare and Move - Same File Name with Different File Extensions


Reply
 
Thread Tools Display Modes
  #1  
Old 02-05-2016, 11:17 AM
sgwilliams sgwilliams is offline
Newcomer
 
Join Date: Feb 2016
Location: North Muskegon, MI
Posts: 2
Question File Compare and Move - Same File Name with Different File Extensions


I'm looking for a VB script or a script of some other flavor that can accomplish the same thing. This is a script that will compare two files in the same folder which have the same file name with different extensions and move the older of the two to a destination folder.

Example filenames are:

example.dwf
example.idw.dwf

Here is the code I have so far for the form I'm working with.
Code:
Imports System.IO
Imports System.ComponentModel

Public Class Form1

    Private Const FOLDERPATH As String = "\\dell2011\engineering\Carter Prints"
    Private _bsFiles As New BindingSource()
    Private _dtFiles As New DataTable()

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        If Not Directory.Exists(FOLDERPATH) Then Throw New Exception("Folder doesn't exist")
        _dtFiles.Columns.Add("FilePath")
        _dtFiles.Columns.Add("FileName")

        RefreshFiles()

        _bsFiles.DataSource = _dtFiles
        ListBox1.DisplayMember = "FileName"
        ListBox1.ValueMember = "FilePath"
        ListBox1.DataSource = _bsFiles
    End Sub

    Private Sub RefreshFiles()
        'loop around each path and loads the files.
        '_files.AddRange(IO.Directory.GetFiles(FOLDERPATH).Where(Function(x)
        '                                                            Dim y = System.IO.Path.GetExtension(x)
        '                                                            Return (New String() {".dwf", ".pdf"}).Contains(y)
        '                                                        End Function) _
        '                                                .Select(Function(x) New FileInformation(x)))

        For Each filePath As String In IO.Directory.GetFiles(FOLDERPATH).Where(Function(x)
                                                                                   Return (New String() {".dwf", ".pdf"}).
                                                                                       Contains(System.IO.Path.GetExtension(x))
                                                                               End Function)
            _dtFiles.Rows.Add(New Object() {filePath, IO.Path.GetFileName(filePath)})
        Next
    End Sub

    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
        If String.IsNullOrWhiteSpace(TextBox1.Text) Then
            _bsFiles.RemoveFilter()
        Else
            _bsFiles.Filter = String.Format("FileName LIKE '%{0}%'", TextBox1.Text)
        End If
    End Sub

    Private Sub ListBox1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles ListBox1.MouseDoubleClick
        Dim theFile = ListBox1.SelectedValue
        If theFile IsNot Nothing Then
            Process.Start(CStr(theFile))
        End If
    End Sub
    Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
            SendKeys.Send("{TAB}")
            e.Handled = True
        End If
    End Sub

    Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click

    End Sub

    Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click

    End Sub
    Private Sub ListBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ListBox1.KeyDown
        Dim theFile = ListBox1.SelectedValue
        If e.KeyCode = Keys.Enter Then
            Process.Start(CStr(theFile))
        End If
    End Sub
    Private WithEvents Tmr As New Timer

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Tmr.Dispose()
    End Sub

    Private Sub CloseWindowToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CloseWindowToolStripMenuItem.Click
        Close()
    End Sub
End Class
If you will notice the files have different extensions some have just a .dwf & others have a double extension that is .idw.dwf. I want to remove both types from the file name so just the part number is left visible in listbox1. There are a couple issues when trying to accomplish this.

Issue one: If I remove both extensions from the current list there will be duplicate values left. The attached image "idw dwf extn.JPG" shows file "C-674-A.dwf" & "C-674-A.idw.dwf". When you remove the extensions from both file names the part number would be the same. One is an old revision of the print, The other is the most recent. This is a problem I need to fix by running a vb script to remove the file with the oldest date when it see's duplicate part numbers. Once the system is cleaned from the duplicate numbers then I can tackle issue 2.

Issue two: When the user does a search for the part number they will be confused by the file extension because it is alien to them as they do not know what it is, nor should they need too. When I changed the IO.Path.GetFileName to IO.Path.GetFileNameWithoutExtension it only removed the last four digits from the file name. This means it removed the ".dwf" from the double file name extension of ".idw.dwf" leaving just the extension ".idw".

See attached image " stripped exten1.PNG" for what the current form looks like running.

I appreciate any help you can give me on this.
Attached Images
File Type: jpg idw dwf extn.JPG (115.2 KB, 0 views)
File Type: png stripped exten1.PNG (530.5 KB, 0 views)
Reply With Quote
Reply

Tags
private, file, object, handles, eventargs, extensions, string, script, extension, remove, .dwf, duplicate, issue, dim, filepath, thefile, files, compare, attached, process.startcstrthefile, move, current, folder, refreshfiles, listbox1.selectedvalue


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
File Compare and Move - Same File Name with Different File Extensions
File Compare and Move - Same File Name with Different File Extensions
File Compare and Move - Same File Name with Different File Extensions File Compare and Move - Same File Name with Different File Extensions
File Compare and Move - Same File Name with Different File Extensions
File Compare and Move - Same File Name with Different File Extensions
File Compare and Move - Same File Name with Different File Extensions File Compare and Move - Same File Name with Different File Extensions File Compare and Move - Same File Name with Different File Extensions File Compare and Move - Same File Name with Different File Extensions File Compare and Move - Same File Name with Different File Extensions File Compare and Move - Same File Name with Different File Extensions File Compare and Move - Same File Name with Different File Extensions
File Compare and Move - Same File Name with Different File Extensions
File Compare and Move - Same File Name with Different File Extensions
 
File Compare and Move - Same File Name with Different File Extensions
File Compare and Move - Same File Name with Different File Extensions
 
-->