File Rename

only Group4 tiff images are allowed to read other are not.

Page 1 of 1

3 Replies - 1692 Views - Last Post: 05 April 2008 - 12:56 AM Rate Topic: -----

#1 RAVI BHATKAL  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-April 08

File Rename

Post icon  Posted 04 April 2008 - 11:30 PM

Imports System.IO
Imports System.Data.OleDb
Imports System.Data
Imports System.Threading
Imports TD

Public Class FileRenamer
    Inherits System.Windows.Forms.Form


    Dim THrename As Thread
    Dim maxrow As Integer
    Dim filecount As Integer
    Dim slno As Integer
    Dim FL As String
    Dim renametable As DataTable
    Dim renameset As DataSet
    Dim renamerow As DataRow
    Dim renamecolumn As DataColumn
    Dim sw As StreamWriter
    Dim conn As New OleDbConnection
    Dim cmd As New OleDbCommand
    Dim dread As OleDbDataReader
    Dim sConnString As String
    Dim sql As String = "select from_list,from_path,to_list,to_path,slno from Renamer_From_To_List"
    Dim count As String = "select count(*) as cnt from Renamer_From_To_List"

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents ContextMenu1 As System.Windows.Forms.ContextMenu
    Friend WithEvents MExit As System.Windows.Forms.MenuItem
    Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip
    Friend WithEvents lblStatus As System.Windows.Forms.Label
    Friend WithEvents pbar As GotXtraCC.XtraProgressBar
    Friend WithEvents btnprievew As System.Windows.Forms.Button
    Friend WithEvents btnexit As System.Windows.Forms.Button
    Friend WithEvents btnrename As System.Windows.Forms.Button
    Friend WithEvents Hcl2 As TD.Eyefinder.HeaderControl
    Friend WithEvents Hcl1 As TD.Eyefinder.HeaderControl
    Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
    Friend WithEvents MRename As System.Windows.Forms.MenuItem
    Friend WithEvents MPrievew As System.Windows.Forms.MenuItem
    Friend WithEvents MHelp As System.Windows.Forms.MenuItem
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.ContextMenu1 = New System.Windows.Forms.ContextMenu
        Me.MRename = New System.Windows.Forms.MenuItem
        Me.MPrievew = New System.Windows.Forms.MenuItem
        Me.MHelp = New System.Windows.Forms.MenuItem
        Me.MExit = New System.Windows.Forms.MenuItem
        Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
        Me.btnprievew = New System.Windows.Forms.Button
        Me.btnexit = New System.Windows.Forms.Button
        Me.btnrename = New System.Windows.Forms.Button
        Me.lblStatus = New System.Windows.Forms.Label
        Me.pbar = New GotXtraCC.XtraProgressBar
        Me.Hcl2 = New TD.Eyefinder.HeaderControl
        Me.Hcl1 = New TD.Eyefinder.HeaderControl
        Me.DataGrid1 = New System.Windows.Forms.DataGrid
        Me.Hcl1.SuspendLayout()
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'ContextMenu1
        '
        Me.ContextMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MRename, Me.MPrievew, Me.MHelp, Me.MExit})
        '
        'MRename
        '
        Me.MRename.Index = 0
        Me.MRename.Shortcut = System.Windows.Forms.Shortcut.CtrlR
        Me.MRename.Text = "Rename"
        '
        'MPrievew
        '
        Me.MPrievew.Index = 1
        Me.MPrievew.Shortcut = System.Windows.Forms.Shortcut.CtrlP
        Me.MPrievew.Text = "Prievew"
        '
        'MHelp
        '
        Me.MHelp.Index = 2
        Me.MHelp.Shortcut = System.Windows.Forms.Shortcut.F1
        Me.MHelp.Text = "Help"
        '
        'MExit
        '
        Me.MExit.Index = 3
        Me.MExit.Shortcut = System.Windows.Forms.Shortcut.CtrlX
        Me.MExit.Text = "Exit"
        '
        'btnprievew
        '
        Me.btnprievew.BackColor = System.Drawing.Color.GhostWhite
        Me.btnprievew.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnprievew.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnprievew.Location = New System.Drawing.Point(240, 40)
        Me.btnprievew.Name = "btnprievew"
        Me.btnprievew.Size = New System.Drawing.Size(105, 22)
        Me.btnprievew.TabIndex = 2
        Me.btnprievew.Text = "Prie&vew"
        Me.ToolTip1.SetToolTip(Me.btnprievew, "To see prievew click here")
        '
        'btnexit
        '
        Me.btnexit.BackColor = System.Drawing.Color.GhostWhite
        Me.btnexit.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.btnexit.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnexit.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnexit.Location = New System.Drawing.Point(352, 40)
        Me.btnexit.Name = "btnexit"
        Me.btnexit.Size = New System.Drawing.Size(57, 22)
        Me.btnexit.TabIndex = 3
        Me.btnexit.Text = "E&xit"
        Me.ToolTip1.SetToolTip(Me.btnexit, "To exit from window click here")
        '
        'btnrename
        '
        Me.btnrename.BackColor = System.Drawing.Color.GhostWhite
        Me.btnrename.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnrename.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnrename.Location = New System.Drawing.Point(168, 40)
        Me.btnrename.Name = "btnrename"
        Me.btnrename.Size = New System.Drawing.Size(65, 22)
        Me.btnrename.TabIndex = 1
        Me.btnrename.Text = "&Proceed"
        Me.ToolTip1.SetToolTip(Me.btnrename, "To rename files click here")
        '
        'lblStatus
        '
        Me.lblStatus.BackColor = System.Drawing.Color.GhostWhite
        Me.lblStatus.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblStatus.Location = New System.Drawing.Point(8, 80)
        Me.lblStatus.Name = "lblStatus"
        Me.lblStatus.Size = New System.Drawing.Size(536, 16)
        Me.lblStatus.TabIndex = 49
        '
        'pbar
        '
        Me.pbar.Location = New System.Drawing.Point(2, 104)
        Me.pbar.Name = "pbar"
        Me.pbar.Size = New System.Drawing.Size(548, 24)
        Me.pbar.TabIndex = 48
        '
        'Hcl2
        '
        Me.Hcl2.BackColor = System.Drawing.Color.GhostWhite
        Me.Hcl2.Dock = System.Windows.Forms.DockStyle.Bottom
        Me.Hcl2.HeaderFont = New System.Drawing.Font("Tahoma", 10.0!, System.Drawing.FontStyle.Bold)
        Me.Hcl2.Location = New System.Drawing.Point(1, 355)
        Me.Hcl2.Name = "Hcl2"
        Me.Hcl2.Size = New System.Drawing.Size(550, 20)
        Me.Hcl2.TabIndex = 37
        '
        'Hcl1
        '
        Me.Hcl1.BackColor = System.Drawing.Color.GhostWhite
        Me.Hcl1.Controls.Add(Me.lblStatus)
        Me.Hcl1.Controls.Add(Me.pbar)
        Me.Hcl1.Controls.Add(Me.DataGrid1)
        Me.Hcl1.Controls.Add(Me.btnprievew)
        Me.Hcl1.Controls.Add(Me.btnexit)
        Me.Hcl1.Controls.Add(Me.btnrename)
        Me.Hcl1.Controls.Add(Me.Hcl2)
        Me.Hcl1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.Hcl1.HeaderFont = New System.Drawing.Font("Tahoma", 10.0!, System.Drawing.FontStyle.Bold)
        Me.Hcl1.Location = New System.Drawing.Point(0, 0)
        Me.Hcl1.Name = "Hcl1"
        Me.Hcl1.Size = New System.Drawing.Size(552, 376)
        Me.Hcl1.TabIndex = 36
        '
        'DataGrid1
        '
        Me.DataGrid1.DataMember = ""
        Me.DataGrid1.Dock = System.Windows.Forms.DockStyle.Bottom
        Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.DataGrid1.Location = New System.Drawing.Point(1, 139)
        Me.DataGrid1.Name = "DataGrid1"
        Me.DataGrid1.Size = New System.Drawing.Size(550, 216)
        Me.DataGrid1.TabIndex = 41
        Me.DataGrid1.Visible = False
        '
        'FileRenamer
        '
        Me.AcceptButton = Me.btnrename
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.GhostWhite
        Me.CancelButton = Me.btnexit
        Me.ClientSize = New System.Drawing.Size(552, 376)
        Me.ContextMenu = Me.ContextMenu1
        Me.Controls.Add(Me.Hcl1)
        Me.MaximizeBox = False
        Me.Name = "FileRenamer"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "File Renamer"
        Me.ToolTip1.SetToolTip(Me, "Press F1 to get help screen")
        Me.Hcl1.ResumeLayout(False)
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

#Region "Initializetheme"
    Friend Sub InitializeTheme()
        With Me.Hcl1
            Dim rdr As Eyefinder.Office2003Renderer
            rdr = CType(.Renderer, Eyefinder.Office2003Renderer)
            rdr.ColorScheme = Eyefinder.Office2003Renderer.Office2003ColorScheme.LunaBlue
        End With
        With Me.Hcl2
            Dim rdr As Eyefinder.Office2003Renderer
            rdr = CType(.Renderer, Eyefinder.Office2003Renderer)
            rdr.ColorScheme = Eyefinder.Office2003Renderer.Office2003ColorScheme.LunaBlue
        End With
    End Sub
#End Region

    Private Sub FileRenamer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        InitializeTheme()
        sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=Input.mdb"
        conn.ConnectionString = sConnString
        conn.Open()
        cmd.Connection = conn
        ' sw = New StreamWriter(New FileStream(" C:\Documents and Settings\Administrator.NWHP03\Desktop\SS\ABC.TXT", FileMode.Create), System.Text.Encoding.Default)
    End Sub

    Private Sub FileRenamer_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        Try
            If MsgBox("Are u sure want to close application?", MsgBoxStyle.YesNo + MsgBoxStyle.Exclamation, Me.Text) = MsgBoxResult.Yes Then
                If conn.State = ConnectionState.Open Then
                    conn.Close()
                End If
                If Not IsNothing(THrename) Then
                    If THrename.ThreadState = ThreadState.Running Then
                        THrename.Suspend()
                    End If
                End If
                End
            Else
                e.Cancel = True
            End If
        Catch exp As Exception
            MessageBox.Show(exp.Message & Microsoft.VisualBasic.ChrW(10) & Microsoft.VisualBasic.ChrW(10) & exp.ToString, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub btnprievew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnprievew.Click
        prievew()
    End Sub

    Private Sub MPrievew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MPrievew.Click
        prievew()
    End Sub

    Private Sub prievew()
        btnrename.Enabled = False
        If btnprievew.Text = "Prie&vew" Then
            If loadgrid() = -1 Then
                Return
            End If
            btnprievew.Text = "Close Prie&vew"
            DataGrid1.Visible = True
        ElseIf btnprievew.Text = "Close Prie&vew" Then
            lblStatus.Text = ""
            btnprievew.Text = "Prie&vew"
            DataGrid1.Visible = False
        End If
        btnrename.Enabled = True
    End Sub

    Private Sub btnrename_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnrename.Click
        rename()
    End Sub

    Private Sub MRename_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MRename.Click
        rename()
    End Sub

    Private Sub rename()
        lblStatus.Text = ""
        btnprievew.Enabled = False
        btnrename.Enabled = False
        btnexit.Enabled = False
        THrename = New Thread(AddressOf renamefile)
        THrename.Start()
    End Sub

    Private Sub btnexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexit.Click
        If Not IsNothing(THrename) Then
            If THrename.ThreadState = ThreadState.Running Then
                THrename.Suspend()
            End If
        End If
        Me.Close()
    End Sub

    Private Sub renamefile()
        'Try

        cmd.CommandText = count
        dread = cmd.ExecuteReader
        dread.Read()
        maxrow = dread.Item(0)
        dread.Close()

        If maxrow = 0 Then
            MsgBox("Input not found", MsgBoxStyle.Critical, Me.Text)
            Return
        End If
        slno = 0
        pbar.BarMin = 0
        pbar.BarMax = maxrow

        cmd.CommandText = sql
        dread = cmd.ExecuteReader
        Dim newdir As DirectoryInfo
        Dim newfile As FileInfo
        Dim inputfile As String
        Dim outputfile As String
        Dim FL As String
        While dread.Read()
            'FL = dread.Item(0)
            'MsgBox(FL)
            newdir = New DirectoryInfo(dread.Item(3))
            If newdir.Exists = False Then
                newdir.Create()
            End If
            newfile = New FileInfo(dread.Item(1) & dread.Item(0))
            If newfile.Exists = True Then
                File.Copy(dread.Item(1) & dread.Item(0), dread.Item(3) & dread.Item(2), True)
                convert(dread.Item(3), dread.Item(2))
            Else
                'MsgBox(newfile.FullName & " file not found" & Microsoft.VisualBasic.ChrW(10) & Microsoft.VisualBasic.ChrW(10) & "Table Name : Renamer_From_To_List. Error at Record No : " & dread.Item(4), MsgBoxStyle.Critical, Me.Text)
                'MsgBox(FL)
                Exit Sub
            End If
            slno = slno + 1
            pbar.BarValue = slno
            lblStatus.Text = "Processing ( " & slno & " of " & maxrow & " )"
        End While
        dread.Close()
        MsgBox("Images renaming successfully completed.................", MsgBoxStyle.Information, Me.Text)
        lblStatus.Text = ""
        btnprievew.Enabled = True
        btnrename.Enabled = True
        btnexit.Enabled = True
        'Catch exp As Exception
        ' MessageBox.Show(exp.Message & Microsoft.VisualBasic.ChrW(10) & Microsoft.VisualBasic.ChrW(10) & exp.ToString, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
        'End Try
    End Sub
    Function convert(ByVal to_path As String, ByVal to_list As String)
        Dim obj As New TIFFDLL80.ClsTIFFDLL
        Dim FL As String
        Dim savefile As String
        Dim result As String
        Dim f_ As FileInfo


        savefile = to_path & to_list
        f_ = New FileInfo(to_list)

        If f_.Extension <> ".jpg" Then
            FL = dread.Item(0)

            obj.FileName_Input = savefile
            obj.FileName_Output = savefile
            'FL = obj.GraphicsFormat
            obj.GraphicsFormat = 114
            ' MsgBox(FL)
            result = obj.Convert()
            If result < 0 Then

                Try

                    ' MsgBox(obj.ImageInfo.ErrorCode & " " & obj.ImageInfo.Error_Location)
                    MsgBox(FL & " " & obj.ImageInfo.Error_Location)

                Catch exc As Exception
                    Console.WriteLine(exc.Message)
                End Try
                Console.Write(vbCrLf & "Press Enter to Continue:")
                Console.Read()
                'sw = New StreamWriter(New FileStream(" C:\Documents and Settings\Administrator.NWHP03\Desktop\SS\ABC.TXT", FileMode.Create), System.Text.Encoding.Default)

            End If
        End If
        
    End Function
    Function loadgrid()
        Try
            lblStatus.Text = ""
            slno = 0
            DataGrid1.TableStyles.Clear()

            renameset = New DataSet("renameset")
            renametable = New DataTable("renametable")
            renamecolumn = New DataColumn("renamefrom")
            renametable.Columns.Add(renamecolumn)
            renamecolumn = New DataColumn("renameto")
            renametable.Columns.Add(renamecolumn)

            cmd.CommandText = count
            dread = cmd.ExecuteReader
            dread.Read()
            maxrow = dread.Item(0)
            dread.Close()
            pbar.BarMin = 0
            pbar.BarMax = maxrow

            cmd.CommandText = sql
            dread = cmd.ExecuteReader
            While dread.Read()
                renamerow = renametable.NewRow
                renamerow("renamefrom") = dread.Item(1) & dread.Item(0)
                renamerow("renameto") = dread.Item(3) & dread.Item(2)
                renametable.Rows.Add(renamerow)
                slno = slno + 1
                pbar.BarValue = slno
                lblStatus.Text = "Processing ( " & slno & " of " & maxrow & " )"
            End While
            dread.Close()
            renameset.Tables.Add(renametable)
            DataGrid1.SetDataBinding(renameset, "renametable")
            With DataGrid1
                .BackColor = Color.GhostWhite
                .BackgroundColor = Color.Lavender
                .BorderStyle = BorderStyle.None
                .CaptionBackColor = Color.RoyalBlue
                .CaptionFont = New Font("Tahoma", 10.0!, FontStyle.Bold)
                .CaptionForeColor = Color.Bisque
                .CaptionText = "Prievew"
                .Font = New Font("Tahoma", 10.0!)
                .ParentRowsBackColor = Color.Lavender
                .ParentRowsForeColor = Color.MidnightBlue
            End With
            Dim grdTableStyle As New DataGridTableStyle
            With grdTableStyle
                .AlternatingBackColor = Color.GhostWhite
                .BackColor = Color.GhostWhite
                .ForeColor = Color.MidnightBlue
                .GridLineColor = Color.RoyalBlue
                .HeaderBackColor = Color.MidnightBlue
                .HeaderFont = New Font("Tahoma", 8.0!, FontStyle.Bold)
                .HeaderForeColor = Color.Lavender
                .AllowSorting = False
                .SelectionBackColor = Color.AntiqueWhite
                .SelectionForeColor = Color.Black
                .MappingName = "renametable"
                .PreferredColumnWidth = 125
                .PreferredRowHeight = 15
            End With
            Dim grdcolstylerenamefrom As New DataGridTextBoxColumn
            With grdcolstylerenamefrom
                .HeaderText = "FROM LIST"
                .MappingName = "renamefrom"
                .Width = 250
                .ReadOnly = True
            End With
            grdTableStyle.GridColumnStyles.Add(grdcolstylerenamefrom)
            Dim grdcolstylerenameto As New DataGridTextBoxColumn
            With grdcolstylerenameto
                .HeaderText = "TO LIST"
                .MappingName = "renameto"
                .Width = 250
                .ReadOnly = True
            End With
            grdTableStyle.GridColumnStyles.Add(grdcolstylerenameto)
            DataGrid1.TableStyles.Add(grdTableStyle)

            Dim cm As CurrencyManager = CType(Me.BindingContext(DataGrid1.DataSource, DataGrid1.DataMember), CurrencyManager)
            CType(cm.List, DataView).AllowNew = False
            lblStatus.Text = ""
        Catch exp As Exception
            MessageBox.Show(exp.Message & Microsoft.VisualBasic.ChrW(10) & Microsoft.VisualBasic.ChrW(10) & exp.ToString, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            btnrename.Enabled = True
        End Try
    End Function

    Private Sub MExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MExit.Click
        Me.Close()
    End Sub


End Class



Please use code tags :) => :code:

This post has been edited by PsychoCoder: 04 April 2008 - 11:32 PM


Is This A Good Question/Topic? 0
  • +

Replies To: File Rename

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: File Rename

Posted 04 April 2008 - 11:33 PM

Is there a question in there somewhere?
Was This Post Helpful? 0
  • +
  • -

#3 RAVI BHATKAL  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-April 08

Re: File Rename

Posted 05 April 2008 - 12:12 AM

View PostRAVI BHATKAL, on 4 Apr, 2008 - 11:30 PM, said:

Imports System.IO
Imports System.Data.OleDb
Imports System.Data
Imports System.Threading
Imports TD

Public Class FileRenamer
    Inherits System.Windows.Forms.Form


    Dim THrename As Thread
    Dim maxrow As Integer
    Dim filecount As Integer
    Dim slno As Integer
    Dim FL As String
    Dim renametable As DataTable
    Dim renameset As DataSet
    Dim renamerow As DataRow
    Dim renamecolumn As DataColumn
    Dim sw As StreamWriter
    Dim conn As New OleDbConnection
    Dim cmd As New OleDbCommand
    Dim dread As OleDbDataReader
    Dim sConnString As String
    Dim sql As String = "select from_list,from_path,to_list,to_path,slno from Renamer_From_To_List"
    Dim count As String = "select count(*) as cnt from Renamer_From_To_List"

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents ContextMenu1 As System.Windows.Forms.ContextMenu
    Friend WithEvents MExit As System.Windows.Forms.MenuItem
    Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip
    Friend WithEvents lblStatus As System.Windows.Forms.Label
    Friend WithEvents pbar As GotXtraCC.XtraProgressBar
    Friend WithEvents btnprievew As System.Windows.Forms.Button
    Friend WithEvents btnexit As System.Windows.Forms.Button
    Friend WithEvents btnrename As System.Windows.Forms.Button
    Friend WithEvents Hcl2 As TD.Eyefinder.HeaderControl
    Friend WithEvents Hcl1 As TD.Eyefinder.HeaderControl
    Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
    Friend WithEvents MRename As System.Windows.Forms.MenuItem
    Friend WithEvents MPrievew As System.Windows.Forms.MenuItem
    Friend WithEvents MHelp As System.Windows.Forms.MenuItem
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.ContextMenu1 = New System.Windows.Forms.ContextMenu
        Me.MRename = New System.Windows.Forms.MenuItem
        Me.MPrievew = New System.Windows.Forms.MenuItem
        Me.MHelp = New System.Windows.Forms.MenuItem
        Me.MExit = New System.Windows.Forms.MenuItem
        Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
        Me.btnprievew = New System.Windows.Forms.Button
        Me.btnexit = New System.Windows.Forms.Button
        Me.btnrename = New System.Windows.Forms.Button
        Me.lblStatus = New System.Windows.Forms.Label
        Me.pbar = New GotXtraCC.XtraProgressBar
        Me.Hcl2 = New TD.Eyefinder.HeaderControl
        Me.Hcl1 = New TD.Eyefinder.HeaderControl
        Me.DataGrid1 = New System.Windows.Forms.DataGrid
        Me.Hcl1.SuspendLayout()
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'ContextMenu1
        '
        Me.ContextMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MRename, Me.MPrievew, Me.MHelp, Me.MExit})
        '
        'MRename
        '
        Me.MRename.Index = 0
        Me.MRename.Shortcut = System.Windows.Forms.Shortcut.CtrlR
        Me.MRename.Text = "Rename"
        '
        'MPrievew
        '
        Me.MPrievew.Index = 1
        Me.MPrievew.Shortcut = System.Windows.Forms.Shortcut.CtrlP
        Me.MPrievew.Text = "Prievew"
        '
        'MHelp
        '
        Me.MHelp.Index = 2
        Me.MHelp.Shortcut = System.Windows.Forms.Shortcut.F1
        Me.MHelp.Text = "Help"
        '
        'MExit
        '
        Me.MExit.Index = 3
        Me.MExit.Shortcut = System.Windows.Forms.Shortcut.CtrlX
        Me.MExit.Text = "Exit"
        '
        'btnprievew
        '
        Me.btnprievew.BackColor = System.Drawing.Color.GhostWhite
        Me.btnprievew.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnprievew.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnprievew.Location = New System.Drawing.Point(240, 40)
        Me.btnprievew.Name = "btnprievew"
        Me.btnprievew.Size = New System.Drawing.Size(105, 22)
        Me.btnprievew.TabIndex = 2
        Me.btnprievew.Text = "Prie&vew"
        Me.ToolTip1.SetToolTip(Me.btnprievew, "To see prievew click here")
        '
        'btnexit
        '
        Me.btnexit.BackColor = System.Drawing.Color.GhostWhite
        Me.btnexit.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.btnexit.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnexit.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnexit.Location = New System.Drawing.Point(352, 40)
        Me.btnexit.Name = "btnexit"
        Me.btnexit.Size = New System.Drawing.Size(57, 22)
        Me.btnexit.TabIndex = 3
        Me.btnexit.Text = "E&xit"
        Me.ToolTip1.SetToolTip(Me.btnexit, "To exit from window click here")
        '
        'btnrename
        '
        Me.btnrename.BackColor = System.Drawing.Color.GhostWhite
        Me.btnrename.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnrename.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnrename.Location = New System.Drawing.Point(168, 40)
        Me.btnrename.Name = "btnrename"
        Me.btnrename.Size = New System.Drawing.Size(65, 22)
        Me.btnrename.TabIndex = 1
        Me.btnrename.Text = "&Proceed"
        Me.ToolTip1.SetToolTip(Me.btnrename, "To rename files click here")
        '
        'lblStatus
        '
        Me.lblStatus.BackColor = System.Drawing.Color.GhostWhite
        Me.lblStatus.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblStatus.Location = New System.Drawing.Point(8, 80)
        Me.lblStatus.Name = "lblStatus"
        Me.lblStatus.Size = New System.Drawing.Size(536, 16)
        Me.lblStatus.TabIndex = 49
        '
        'pbar
        '
        Me.pbar.Location = New System.Drawing.Point(2, 104)
        Me.pbar.Name = "pbar"
        Me.pbar.Size = New System.Drawing.Size(548, 24)
        Me.pbar.TabIndex = 48
        '
        'Hcl2
        '
        Me.Hcl2.BackColor = System.Drawing.Color.GhostWhite
        Me.Hcl2.Dock = System.Windows.Forms.DockStyle.Bottom
        Me.Hcl2.HeaderFont = New System.Drawing.Font("Tahoma", 10.0!, System.Drawing.FontStyle.Bold)
        Me.Hcl2.Location = New System.Drawing.Point(1, 355)
        Me.Hcl2.Name = "Hcl2"
        Me.Hcl2.Size = New System.Drawing.Size(550, 20)
        Me.Hcl2.TabIndex = 37
        '
        'Hcl1
        '
        Me.Hcl1.BackColor = System.Drawing.Color.GhostWhite
        Me.Hcl1.Controls.Add(Me.lblStatus)
        Me.Hcl1.Controls.Add(Me.pbar)
        Me.Hcl1.Controls.Add(Me.DataGrid1)
        Me.Hcl1.Controls.Add(Me.btnprievew)
        Me.Hcl1.Controls.Add(Me.btnexit)
        Me.Hcl1.Controls.Add(Me.btnrename)
        Me.Hcl1.Controls.Add(Me.Hcl2)
        Me.Hcl1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.Hcl1.HeaderFont = New System.Drawing.Font("Tahoma", 10.0!, System.Drawing.FontStyle.Bold)
        Me.Hcl1.Location = New System.Drawing.Point(0, 0)
        Me.Hcl1.Name = "Hcl1"
        Me.Hcl1.Size = New System.Drawing.Size(552, 376)
        Me.Hcl1.TabIndex = 36
        '
        'DataGrid1
        '
        Me.DataGrid1.DataMember = ""
        Me.DataGrid1.Dock = System.Windows.Forms.DockStyle.Bottom
        Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.DataGrid1.Location = New System.Drawing.Point(1, 139)
        Me.DataGrid1.Name = "DataGrid1"
        Me.DataGrid1.Size = New System.Drawing.Size(550, 216)
        Me.DataGrid1.TabIndex = 41
        Me.DataGrid1.Visible = False
        '
        'FileRenamer
        '
        Me.AcceptButton = Me.btnrename
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.GhostWhite
        Me.CancelButton = Me.btnexit
        Me.ClientSize = New System.Drawing.Size(552, 376)
        Me.ContextMenu = Me.ContextMenu1
        Me.Controls.Add(Me.Hcl1)
        Me.MaximizeBox = False
        Me.Name = "FileRenamer"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "File Renamer"
        Me.ToolTip1.SetToolTip(Me, "Press F1 to get help screen")
        Me.Hcl1.ResumeLayout(False)
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

#Region "Initializetheme"
    Friend Sub InitializeTheme()
        With Me.Hcl1
            Dim rdr As Eyefinder.Office2003Renderer
            rdr = CType(.Renderer, Eyefinder.Office2003Renderer)
            rdr.ColorScheme = Eyefinder.Office2003Renderer.Office2003ColorScheme.LunaBlue
        End With
        With Me.Hcl2
            Dim rdr As Eyefinder.Office2003Renderer
            rdr = CType(.Renderer, Eyefinder.Office2003Renderer)
            rdr.ColorScheme = Eyefinder.Office2003Renderer.Office2003ColorScheme.LunaBlue
        End With
    End Sub
#End Region

    Private Sub FileRenamer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        InitializeTheme()
        sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=Input.mdb"
        conn.ConnectionString = sConnString
        conn.Open()
        cmd.Connection = conn
        ' sw = New StreamWriter(New FileStream(" C:\Documents and Settings\Administrator.NWHP03\Desktop\SS\ABC.TXT", FileMode.Create), System.Text.Encoding.Default)
    End Sub

    Private Sub FileRenamer_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        Try
            If MsgBox("Are u sure want to close application?", MsgBoxStyle.YesNo + MsgBoxStyle.Exclamation, Me.Text) = MsgBoxResult.Yes Then
                If conn.State = ConnectionState.Open Then
                    conn.Close()
                End If
                If Not IsNothing(THrename) Then
                    If THrename.ThreadState = ThreadState.Running Then
                        THrename.Suspend()
                    End If
                End If
                End
            Else
                e.Cancel = True
            End If
        Catch exp As Exception
            MessageBox.Show(exp.Message & Microsoft.VisualBasic.ChrW(10) & Microsoft.VisualBasic.ChrW(10) & exp.ToString, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub btnprievew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnprievew.Click
        prievew()
    End Sub

    Private Sub MPrievew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MPrievew.Click
        prievew()
    End Sub

    Private Sub prievew()
        btnrename.Enabled = False
        If btnprievew.Text = "Prie&vew" Then
            If loadgrid() = -1 Then
                Return
            End If
            btnprievew.Text = "Close Prie&vew"
            DataGrid1.Visible = True
        ElseIf btnprievew.Text = "Close Prie&vew" Then
            lblStatus.Text = ""
            btnprievew.Text = "Prie&vew"
            DataGrid1.Visible = False
        End If
        btnrename.Enabled = True
    End Sub

    Private Sub btnrename_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnrename.Click
        rename()
    End Sub

    Private Sub MRename_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MRename.Click
        rename()
    End Sub

    Private Sub rename()
        lblStatus.Text = ""
        btnprievew.Enabled = False
        btnrename.Enabled = False
        btnexit.Enabled = False
        THrename = New Thread(AddressOf renamefile)
        THrename.Start()
    End Sub

    Private Sub btnexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexit.Click
        If Not IsNothing(THrename) Then
            If THrename.ThreadState = ThreadState.Running Then
                THrename.Suspend()
            End If
        End If
        Me.Close()
    End Sub

    Private Sub renamefile()
        'Try

        cmd.CommandText = count
        dread = cmd.ExecuteReader
        dread.Read()
        maxrow = dread.Item(0)
        dread.Close()

        If maxrow = 0 Then
            MsgBox("Input not found", MsgBoxStyle.Critical, Me.Text)
            Return
        End If
        slno = 0
        pbar.BarMin = 0
        pbar.BarMax = maxrow

        cmd.CommandText = sql
        dread = cmd.ExecuteReader
        Dim newdir As DirectoryInfo
        Dim newfile As FileInfo
        Dim inputfile As String
        Dim outputfile As String
        Dim FL As String
        While dread.Read()
            'FL = dread.Item(0)
            'MsgBox(FL)
            newdir = New DirectoryInfo(dread.Item(3))
            If newdir.Exists = False Then
                newdir.Create()
            End If
            newfile = New FileInfo(dread.Item(1) & dread.Item(0))
            If newfile.Exists = True Then
                File.Copy(dread.Item(1) & dread.Item(0), dread.Item(3) & dread.Item(2), True)
                convert(dread.Item(3), dread.Item(2))
            Else
                'MsgBox(newfile.FullName & " file not found" & Microsoft.VisualBasic.ChrW(10) & Microsoft.VisualBasic.ChrW(10) & "Table Name : Renamer_From_To_List. Error at Record No : " & dread.Item(4), MsgBoxStyle.Critical, Me.Text)
                'MsgBox(FL)
                Exit Sub
            End If
            slno = slno + 1
            pbar.BarValue = slno
            lblStatus.Text = "Processing ( " & slno & " of " & maxrow & " )"
        End While
        dread.Close()
        MsgBox("Images renaming successfully completed.................", MsgBoxStyle.Information, Me.Text)
        lblStatus.Text = ""
        btnprievew.Enabled = True
        btnrename.Enabled = True
        btnexit.Enabled = True
        'Catch exp As Exception
        ' MessageBox.Show(exp.Message & Microsoft.VisualBasic.ChrW(10) & Microsoft.VisualBasic.ChrW(10) & exp.ToString, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
        'End Try
    End Sub
    Function convert(ByVal to_path As String, ByVal to_list As String)
        Dim obj As New TIFFDLL80.ClsTIFFDLL
        Dim FL As String
        Dim savefile As String
        Dim result As String
        Dim f_ As FileInfo


        savefile = to_path & to_list
        f_ = New FileInfo(to_list)

        If f_.Extension <> ".jpg" Then
            FL = dread.Item(0)

            obj.FileName_Input = savefile
            obj.FileName_Output = savefile
            'FL = obj.GraphicsFormat
            obj.GraphicsFormat = 114
            ' MsgBox(FL)
            result = obj.Convert()
            If result < 0 Then

                Try

                    ' MsgBox(obj.ImageInfo.ErrorCode & " " & obj.ImageInfo.Error_Location)
                    MsgBox(FL & " " & obj.ImageInfo.Error_Location)

                Catch exc As Exception
                    Console.WriteLine(exc.Message)
                End Try
                Console.Write(vbCrLf & "Press Enter to Continue:")
                Console.Read()
                'sw = New StreamWriter(New FileStream(" C:\Documents and Settings\Administrator.NWHP03\Desktop\SS\ABC.TXT", FileMode.Create), System.Text.Encoding.Default)

            End If
        End If
        
    End Function
    Function loadgrid()
        Try
            lblStatus.Text = ""
            slno = 0
            DataGrid1.TableStyles.Clear()

            renameset = New DataSet("renameset")
            renametable = New DataTable("renametable")
            renamecolumn = New DataColumn("renamefrom")
            renametable.Columns.Add(renamecolumn)
            renamecolumn = New DataColumn("renameto")
            renametable.Columns.Add(renamecolumn)

            cmd.CommandText = count
            dread = cmd.ExecuteReader
            dread.Read()
            maxrow = dread.Item(0)
            dread.Close()
            pbar.BarMin = 0
            pbar.BarMax = maxrow

            cmd.CommandText = sql
            dread = cmd.ExecuteReader
            While dread.Read()
                renamerow = renametable.NewRow
                renamerow("renamefrom") = dread.Item(1) & dread.Item(0)
                renamerow("renameto") = dread.Item(3) & dread.Item(2)
                renametable.Rows.Add(renamerow)
                slno = slno + 1
                pbar.BarValue = slno
                lblStatus.Text = "Processing ( " & slno & " of " & maxrow & " )"
            End While
            dread.Close()
            renameset.Tables.Add(renametable)
            DataGrid1.SetDataBinding(renameset, "renametable")
            With DataGrid1
                .BackColor = Color.GhostWhite
                .BackgroundColor = Color.Lavender
                .BorderStyle = BorderStyle.None
                .CaptionBackColor = Color.RoyalBlue
                .CaptionFont = New Font("Tahoma", 10.0!, FontStyle.Bold)
                .CaptionForeColor = Color.Bisque
                .CaptionText = "Prievew"
                .Font = New Font("Tahoma", 10.0!)
                .ParentRowsBackColor = Color.Lavender
                .ParentRowsForeColor = Color.MidnightBlue
            End With
            Dim grdTableStyle As New DataGridTableStyle
            With grdTableStyle
                .AlternatingBackColor = Color.GhostWhite
                .BackColor = Color.GhostWhite
                .ForeColor = Color.MidnightBlue
                .GridLineColor = Color.RoyalBlue
                .HeaderBackColor = Color.MidnightBlue
                .HeaderFont = New Font("Tahoma", 8.0!, FontStyle.Bold)
                .HeaderForeColor = Color.Lavender
                .AllowSorting = False
                .SelectionBackColor = Color.AntiqueWhite
                .SelectionForeColor = Color.Black
                .MappingName = "renametable"
                .PreferredColumnWidth = 125
                .PreferredRowHeight = 15
            End With
            Dim grdcolstylerenamefrom As New DataGridTextBoxColumn
            With grdcolstylerenamefrom
                .HeaderText = "FROM LIST"
                .MappingName = "renamefrom"
                .Width = 250
                .ReadOnly = True
            End With
            grdTableStyle.GridColumnStyles.Add(grdcolstylerenamefrom)
            Dim grdcolstylerenameto As New DataGridTextBoxColumn
            With grdcolstylerenameto
                .HeaderText = "TO LIST"
                .MappingName = "renameto"
                .Width = 250
                .ReadOnly = True
            End With
            grdTableStyle.GridColumnStyles.Add(grdcolstylerenameto)
            DataGrid1.TableStyles.Add(grdTableStyle)

            Dim cm As CurrencyManager = CType(Me.BindingContext(DataGrid1.DataSource, DataGrid1.DataMember), CurrencyManager)
            CType(cm.List, DataView).AllowNew = False
            lblStatus.Text = ""
        Catch exp As Exception
            MessageBox.Show(exp.Message & Microsoft.VisualBasic.ChrW(10) & Microsoft.VisualBasic.ChrW(10) & exp.ToString, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            btnrename.Enabled = True
        End Try
    End Function

    Private Sub MExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MExit.Click
        Me.Close()
    End Sub


End Class



Please use code tags :) => :code:

Was This Post Helpful? 0
  • +
  • -

#4 RodgerB  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 66
  • View blog
  • Posts: 2,284
  • Joined: 21-September 07

Re: File Rename

Posted 05 April 2008 - 12:56 AM

We are not Doctors here at </dream.in.code>. We will not conduct tests for you unless prompted to do so, with very definitive reasoning and effort shown on your part to get whatever you need tested and fixed.

Please post what you ask of us to check, including errors, sections that need attention and questions you may have on whatever subject this may be. Provide us with as much information as you can possible, to receive any sort of answer.

Thank you for your cooperation.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1