Directory and File. Access Files in a Directory Name space: System.IO The Directory and File classes contain only shared methods that set or return information.

Slides:



Advertisements
Similar presentations
Midterm 26 March 2015 (4:30-5:30 pm) – Rm5620 Closed book exam MC Questions only x25 Up to L(7) Methods Scope: video lectures (+Lab), forum discussions,
Advertisements

Practical Programming COMP153-08S Lecture: Repetition Continued.
Creating Custom Controls ISYS 512/812. Inheritance The process in which a new class can be based on an existing class, and will inherit that class’s interface.
VB.Net Loops.
Common Windows Controls. Objectives Learn about common Windows controls Load, display, and share images with other control instances using the ImageList.
Compunet Corporation Programming with Visual Studio.NET GUI Week 13 Tariq Aziz and Kevin Jones.
File dialog boxes Function args and overloading. Examples in this show List directory contents Open a file for viewing Read/Write to a file Add file I/O.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
Multiple Forms & Procedures. Form Methods: –Show, Hide, Activate, Close Events: –Load, Activated, Closing, Closed.
More on lists, exceptions, loops and validation. You can use the exception to indicate the error that occurred Private Sub btnCheck_Click(ByVal sender.
Inheritance and User-Defined Controls. Inheritance The process in which a new class can be based on an existing class, and will inherit that class’s interface.
1 Multiple Document Interface (MDI) Windows. Single Document Interface (SDI) A program that can only support one open window or a document For Example,
VB.Net Loops. Loop FOR index – start TO end [STEP step] [statements] [EXIT FOR] NEXT index DO [{WHILE| UNTIL} condition] [statements] [EXIT DO] LOOP.
File and Streams There are many ways of organizing records in a file. There are many ways of organizing records in a file. The most common type of organization.
XML Web Services Tuc Goodwin 8/10/ Agenda Review: What is an XML Web Service? Review Steps to calling a Web Service SharePoint Web Services.
Visual Basic 2008 Express Edition The IDE. Visual Basic 2008 Express The Start Page Recent Projects Open an existing project Create a New Project.
Menus,MonthCalender, DateTimePicker, MDI,Tree View, List View,
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Assignment #1 Advanced Computer Programming.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide.
Lecture 8 Visual Basic (2).
COMPUTER PROGRAMMING I Objective 7.03 Apply Built-in Math Class Functions.
1/31 5/6/2014 BAZELE PROGRMARII PE OBIECTE PROIECTE IN VISUAL BASIC Conf univ dr Botezatu Cezar INFORMATICĂ MANAGERIALĂ Anul I. STUDII DE LICENŢĂ.
1 CC111 Lec9 : Visual Basic Visual Basic (3) Lecture 9.
VB Procedures. Procedures. Sub procedure: Private/Public Sub SubName(Arguments) … End Sub Private: Can only be accessed by procedures in the same form.
Recursive Functions Creating Hierarchical Reports Date: 9/30/2008 Dan McCreary President Dan McCreary & Associates (952) M.
1 COMP3100e Developing Microsoft.Net Applications for Windows (Visual Basic.Net) Class 6 COMP3100E.
CIS 338: Classes and Modules Dr. Ralph D. Westfall May, 2011.
IMS 3253: Subroutines 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Procedures Subroutines Parameters –By Value.
CS0004: Introduction to Programming Project 1 – Lessons Learned.
ADO.NET Objects – Data Providers Dr. Ron Eaglin. Requirements Visual Studio 2005 Microsoft SQL Server 2000 or 2005 –Adventure Works Database Installed.
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 10: Chapter 6: Slide 1 Unit 10 Sub Procedures and Functions Chapter 6 Sub.
6c – Function Procedures Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
COPYRIGHT 2010: Dr. David Scanlan, CSUS OBJECTIVES: How to write classes How to create an object from a class using the "New" keyword. How to communicate.
HNDIT Rapid Application Development
Created by Alia Al-Abdulkarim 2008 Visual Basic Vs. Java.
1 CS387/CS587: Note04 Lab 3. 2 Master Page All Web pages will be similar Should be created before other web pages Add New Items Controls on the Master.
Creating Menus Menu Bar – behaves like standard Windows menus Can be used in place of or in addition to buttons to execute a procedure Menu items are controls.
Using ADO.Net to Build a Login System Dr. Ron Eaglin.
Lab 10 Slides.
XML Web Services Tuc Goodwin 2/9/ Agenda What is an XML Web Service? Web Services Business Benefits Changing Application Architectural Model Web.
ADO.NET Objects Data Adapters Dr. Ron Eaglin. Agenda Builds on Information in Part I Should have working knowledge of creating a database connection Continuation.
Introduction to VB programming Dr. John P. Abraham UTPA Chapters 2 & 3.
Starting Out with Visual Basic.NET 2 nd Edition Chapter 6 Sub Procedures And Functions.
Files and Streams. What is a file? Up until now, any stored data within a program is lost when the program closes. A file is a permanent way to store.
Graphical User Interfaces Part 2 1 Outline TreeViews ListViews Tab Control.
18-1 Chapter 18 Binary Trees Data Structures and Design in Java © Rick Mercer.
These materials where developed by Martin Schray. Please feel free to use and modify them for non-commercial purposes. If you find them useful or would.
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
Computer Science Up Down Controls, Decisions and Random Numbers.
Directory and File. Access Files in a Directory Name space: System.IO The Directory and File classes contain only shared methods that set or return information.
COMPUTER PROGRAMMING I Apply Procedures to Develop List Box and Combo Box Objects.
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Chapter 9 S. NandaGopalan, BIT
Apply Procedures to Develop Message, Input, and Dialog Boxes
Visual Basic 2010 Winsock이용
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Introduction to VB programming
Files and Streams.
TreeView Control.
للمزيد زورونا على موقعنا الإلكتروني:
Boolean Expressions and If statements
Windows Forms GUI: A Deeper Look
1.الدوال Function 2.الاجراءاتSub Procedure 3.وحده نمطيه Add Module
CIS16 Application Development and Programming using Visual Basic.net
XML Kunwar Singh.
CIS 338: Images on Forms Dr. Ralph D. Westfall May, 2009.
Files and Streams.
GUI Programming in Visual Studio .NET
Web Service.
Presentation transcript:

Directory and File

Access Files in a Directory Name space: System.IO The Directory and File classes contain only shared methods that set or return information about entries in the file system. Shared methods can be called without instantiating an object of that class.

Directory Class Methods: –SetCurrentDirectory Dim currDir As String = "c:\inetpub\mailroot\drop" Directory.SetCurrentDirectory(currDir) –GetDirectories: Returns an array of sub directory names in the current directory Directory.GetDirectories(currDir) –GetFiles: Returns an array of file names Directory.GetFiles(currDir, "*.eml")

GetDirectory Example Dim currDir As String = "C:\teaching" Directory.SetCurrentDirectory(currDir) Dim results As String Dim folder As String For Each folder In Directory.GetDirectories(currDir) results = results & folder & vbCrLf Next MessageBox.Show(results)

File Class Methods: –GetCreationTime –GetLastAccessTime –GetLastWriteTime –GetAttributes

Dim currDir As String = "c" Directory.SetCurrentDirectory(currDir) Dim nFile As Integer nFile = Directory.GetFiles(currDir).GetUpperBound(0) Dim fName, fPath As String For Each fName In Directory.GetFiles(currDir, "*.txt") ListBox1.Items.Add(fName) ListBox1.Items.Add(File.GetCreationTime(fName).ToLongDateString()) ListBox1.Items.Add(File.GetLastAccessTime(fName).ToLongDateString) ListBox1.Items.Add(File.GetLastWriteTime(fName).ToLongDateString) Next

TreeView Control Drill Down interface Displays information in a hierarchical manner. Nodes collection: –Root: No parent –Other nodes have a single parent. –Siblings: Children have the same parent. First Sibling, Last Sibling TreeNode Editor

TreeView Properties TopNode Nodes –Nodes(Index) GetNodeCount(False) SelectedNode –FullPath

Display Root Node’s Children Dim TrNode As TreeNode For Each TrNode In TreeView1.TopNode.Nodes MessageBox.Show(TrNode.Text) MessageBox.Show(TrNode.FullPath) Nextree Note: Nodes is a collection of children nodes directly belong to a parent node.

Displaying Selected Node’s Information Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect MessageBox.Show(TreeView1.SelectedNode.Text) MessageBox.Show(TreeView1.SelectedNode.FullPath()) End Sub

Adding a TreeNode Programmatically Nodes collection’s Add method: –Add(string) TreeView1.Nodes.Add("Root") –Add(a tree node) Define a tree node object Dim myNode As New TreeNode() myNode.Text = "Root" TreeView1.Nodes.Add(myNode)

TreeView1.Nodes.Add("Root") TreeView1.Nodes(0).Nodes.Add("Child1") TreeView1.Nodes(0).Nodes.Add("Child2") TreeView1.Nodes(0).Nodes.Add("child3") TreeView1.Nodes(0).Nodes(0).Nodes.Add("GrandC11") TreeView1.Nodes(0).Nodes(0).Nodes.Add("GrandC12") TreeView1.Nodes(0).Nodes(1).Nodes.Add("GrandC21") TreeView1.Nodes(0).Nodes(2).Nodes.Add("GrandC31") TreeView1.Nodes(0).Nodes(2).Nodes.Add("GrandC32") TreeView1.Nodes(0).Nodes(2).Nodes(0).Nodes.Add("GGrandC311")

Recursive Procedure A procedure that calls itself.

Creating a TreeView of Directories Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim DiskDrive As String = "C:\" TreeView1.Nodes.Add(DiskDrive) Call GetFolders(TreeView1.Nodes(0)) End Sub Private Sub GetFolders(ByVal CurrentFolder As TreeNode) Dim FolderPath As String FolderPath = CurrentFolder.Text Dim folder As String If Directory.GetDirectories(FolderPath).Length <> 0 Then For Each folder In Directory.GetDirectories(FolderPath) Dim newNode As New TreeNode(folder) CurrentFolder.Nodes.Add(newNode) Call GetFolders(newNode) Next End If End Sub

Displaying Files in Selected Folder Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect Dim currDir As String currDir = TreeView1.SelectedNode.Text Dim fName As String ListBox1.Items.Clear() For Each fName In Directory.GetFiles(currDir) ListBox1.Items.Add(fName) Next End Sub