Help in File Info
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Help in File Info

  1. #1
    Join Date
    Jul 2011
    Posts
    3

    Help in File Info

    Hi, i am very new to VB. I am working on file operation such as show files, copy file, delete file, show current directory, rename folder, make folder.

    My problem right now is with delete and copy file. I have a method of delete and copy but i dont know how to pass this method on a button.

    Because we are told that each file operation should have a button for their specific purposes.

    Here is my simple gui with 3 buttons which i have made so far. I am using vb2010.



    http://www.flickr.com/photos/tiwnet/5964183989/


    Public Sub DeleteFilesFromFolders(ByVal sourcePath As String)
    If (Directory.Exists(DirPath)) Then
    For Each fName As String In Directory.GetFiles(DirPath)
    If File.Exists(fName) Then
    File.Delete(fName)
    End If
    Next
    End If
    End Sub

    Hope you could help me. tnx in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,961

    Re: Help in File Info

    Take a look in my signature, for the 101 VB.Net Samples (for each version of VS)

    There are controls to help with this task...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,813

    Re: Help in File Info

    It is very simple, click your button in the designer and the code window will open with the cursor set in the button click event there you will add code to call your sub rountine

    simply use the name of the sub or function and any parameters it may require.

    Code:
    DeleteFilesFromFolders(MyPath)
    Always use [code][/code] tags when posting code.

  4. #4
    Join Date
    Jul 2011
    Posts
    3

    Re: Help in File Info

    Hi dglienna,

    I followed your link and run the program filesystemsample but there were some errors in it particularly in copy file, delete file, move file which shows the error "Requested value 'False' was not found.

    I hope you could help me again in this issue? tnx in advance .

  5. #5
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,090

    Re: Help in File Info

    It would help us if you include some code in your posts.

  6. #6
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,961

    Re: Help in File Info

    Hope you got the RIGHT VERSION for VSxx
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Jul 2011
    Posts
    3

    Re: Help in File Info

    Hi HanneSThEGreaT,

    Here is the code in CopyFilePanel

    The error that comes out when i click the execute button, it shows the error "Requested value 'False' was not found.

    Here's the main form of it.. http://www.flickr.com/photos/tiwnet/5980771259/

    @dglienna

    Yes i checked it and it supports the visual basic 2010 which i am using, i just don't know why it went wrong, your given link should have been perfect if not for this error.

    tnx anyway, now my problem is to find its cause.


    Imports Microsoft.VisualBasic.FileIO

    Public Class CopyFilePanel
    Inherits FileSystemSample.TaskPanelBase

    #Region " Windows Form Designer generated code "

    Private 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.
    <System.Diagnostics.DebuggerNonUserCode()> Private Sub InitializeComponent()
    '
    'DescriptionTextBox
    '
    Me.DescriptionTextBox.AutoSize = False
    Me.DescriptionTextBox.Location = New System.Drawing.Point(7, 20)
    Me.DescriptionTextBox.Multiline = True
    Me.DescriptionTextBox.Size = New System.Drawing.Size(568, 61)
    Me.DescriptionTextBox.Text = "My.Computer.FileSystem.CopyFile copies from one location to another. It exposes " & _
    "functionality to rename file during the copy, show the Windows Shell dialog, and" & _
    " overwrite the existing file in the target directory, if any."
    '
    'ExececuteMethodButton
    '
    '
    'ResetValuesButton
    '
    '
    'CopyFilePanel
    '
    Me.Name = "CopyFilePanel"

    End Sub

    #End Region


    Private Shared panelInstance As CopyFilePanel
    Friend WithEvents sourceFileChooser As New FileChooser()
    Friend WithEvents targetChooser As New DirectoryChooser()
    Friend WithEvents newNameTextBox As New TextBox()
    Friend WithEvents overWriteComboBox As New ComboBox()
    Friend WithEvents showUIComboBox As New ComboBox()
    Friend WithEvents onUserCancelComboBox As New ComboBox()

    ''' <summary>
    ''' Return a global instance of this panel.
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function GetInstance() As CopyFilePanel
    If (panelInstance Is Nothing) Then
    panelInstance = New CopyFilePanel()
    End If
    Return panelInstance
    End Function

    ''' <summary>
    ''' Load the panel, adding controls to the panel for each parameter to copyDirectory
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub CopyFilePanel_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    InitializeUserControls()
    MyBase.AddParameter("sourceFileName", sourceFileChooser)
    MyBase.AddParameter("destinationFileName", targetChooser)
    MyBase.AddParameter("showUI", showUIComboBox)
    MyBase.AddParameter("onUserCancel", onUserCancelComboBox)
    End Sub

    ''' <summary>
    ''' When the user selects a filename, automatically set the newName parameter to the filename they selected.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub sourceFileChooser_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles sourceFileChooser.Leave
    If (Me.sourceFileChooser.Filename <> String.Empty) Then
    Me.newNameTextBox.Text = System.IO.Path.GetFileName(Me.sourceFileChooser.Filename)
    End If
    End Sub


    ''' <summary>
    ''' Initialize each control with all possible parameter values
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub InitializeUserControls()
    MyBase.MethodNameLabel.Text = "My.Computer.FileSystem.CopyFile("

    Me.sourceFileChooser.Reset()
    Me.targetChooser.Reset()
    Me.newNameTextBox.Text = String.Empty

    overWriteComboBox.Items.AddRange(New String() {"True", "False"})
    overWriteComboBox.AutoSize = True
    overWriteComboBox.SelectedItem = "False"
    overWriteComboBox.DropDownStyle = ComboBoxStyle.DropDownList

    showUIComboBox.Items.AddRange(New String() {"True", "False"})
    showUIComboBox.AutoSize = True
    showUIComboBox.SelectedItem = "False"
    showUIComboBox.DropDownStyle = ComboBoxStyle.DropDownList

    onUserCancelComboBox.Items.AddRange(New String() {"Do Nothing", "Throw Exception"})
    onUserCancelComboBox.AutoSize = True
    onUserCancelComboBox.SelectedItem = "Throw Exception"
    onUserCancelComboBox.DropDownStyle = ComboBoxStyle.DropDownList

    End Sub

    ''' <summary>
    ''' Copy the file using the parameters specified.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub ExececuteMethodButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExececuteMethodButton.Click
    Try
    My.Computer.FileSystem.CopyFile( _
    sourceFileName:=Me.sourceFileChooser.Filename, _
    destinationFileName:=Me.targetChooser.Directory, _
    showUI:=CType(UIOption.Parse(GetType(UIOption), CType(Me.showUIComboBox.SelectedItem, String)), UIOption), _
    onUserCancel:=ParseUICancelOption(Me.onUserCancelComboBox))
    Catch ex As Exception
    MessageBox.Show(ex.Message)
    End Try
    End Sub

    Private Sub ResetValuesButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ResetValuesButton.Click
    InitializeUserControls()
    End Sub
    End Class

  8. #8
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,961

    Re: Help in File Info

    Nobody is going to try to read that mess. Look at Post #3, to see how to enclose it in CODE tags. Then, we'll look at it.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  9. #9
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,090

    Re: Help in File Info


Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center