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.
Making a cartoon or slideshow. Aside VB comments An apostrophe starts a comment to end of line Some of the following slides have code with comments in.
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.
VB Classes - 2 ISYS 573. Creating an Array of Objects Dim emps(2) As emp Dim i As Integer For i = 0 To emps.GetUpperBound(0) emps(i) = New emp() Next.
VB.NET Database Tools ISYS Net Applications OLE DB Provider OLE DB Data Source OLE DB Provider ODBC Data Source SQL Server Data Source SQL Server.Net.
VB Collection Data Structures. Array ArrayList HashTable VB6 Collection Others:SortedList, Stack, Queue.
Brinkmann CS522 Dec Web Services Dave Brinkmann.
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.
VB Classes - 2 ISYS 573. Creating an Array of Objects Dim emps(2) As emp Dim i As Integer For i = 0 To emps.GetUpperBound(0) emps(i) = New emp() Next.
Coding ADO.Net DataSet Objects. DataSet Object A DataSet object can hold several tables and relationships between tables. A DataSet is a set of disconnedted.
Coding ADO.NET Objects: Connection, Command, DataReader.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
An array of controls Not particularly convenient in VB Examples: array of pictureboxes Array of textboxes Notes on Concentration game (a possible final.
Coding ADO.Net DataSet Objects. DataSet Object A DataSet object can hold several tables and relationships between tables. A DataSet is a set of disconnedted.
VB.NET Database Tools ISYS 573. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
ASP.NET and ADO.NET. Bind the DataReader to a DataGrid Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\sales2k.mdb" Dim objConn.
Arrays. Declaring a Array With subscript: –Dim numbers(2) as Integer –Using variable as subscript: Dim arrayIndex as Integer = 10 Dim myArray(arrayIndex)
Coding ADO.NET Objects: Connection, Command, DataReader.
More on lists, exceptions, loops and validation. You can use the exception to indicate the error that occurred Private Sub btnCheck_Click(ByVal sender.
Working with Session. Postback and Variables Variables declared in a web page including ADO.Net objects may be reinitialized and lose their values.
A short ppt Importing images Changing fonts. Getting images.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
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.
Arrays One dimensional arrays. Index of projects Random picture display Sum array values Display names in listbox Name search Largest/smallest Car sales.
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.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Visual Basic 2008 Express Edition The IDE. Visual Basic 2008 Express The Start Page Recent Projects Open an existing project Create a New Project.
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 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.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Visual Basic.NET Windows Forms Hello World Homework Assignment.
1 COMP3100e Developing Microsoft.Net Applications for Windows (Visual Basic.Net) Class 6 COMP3100E.
File I/O What We’ll Cover –Visual Basic Techniques for Text Files –.NET Techniques for Text Files What We’ll Not Cover –Binary File I/O –XML File I/O.
CS0004: Introduction to Programming Project 1 – Lessons Learned.
Objects andVB Classes ISYS 350. What Is an Object? Objects are key to understanding object-oriented technology. There are many examples of real-world.
6c – Function Procedures Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
PRACTICE SAC 1 Some solutions. 'inputs 'sale price 'postcode 'coupon codes 'processing 'calculate commissions (commission based on cost) 'calculate postage.
Created by Alia Al-Abdulkarim 2008 Visual Basic Vs. Java.
Lab 10 Slides.
Objects andVB Classes ISYS 350. What Is an Object? Objects are key to understanding object-oriented technology. There are many examples of real-world.
Practical Programming COMP153-08S Lecture: Repetition.
Introduction to VB programming Dr. John P. Abraham UTPA Chapters 2 & 3.
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.
T HE W ALKING FOR W ATER P ROJECT IE 2060 Katelyn Cockrell Alexis Duran Theresa Garcia.
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 Programming For CCS 301 course Dr. Ahmad ABDELHAY.
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.
VB.NET User Interface Controls. VB User Interface Objects Form InputBox, MessageBox Standard Controls: –TextBox, MaskedTextBox, List Box, Option Button,
Coding ADO.NET Objects: Connection, Command, DataReader
Apply Procedures to Develop Menus, List Box and Combo Box Objects
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.
للمزيد زورونا على موقعنا الإلكتروني:
1.الدوال Function 2.الاجراءاتSub Procedure 3.وحده نمطيه Add Module
Chapter 3.5 Input and Output
Input and Output.
Coding ADO.NET Objects: Connection, Command, DataReader
Input and Output.
Files and Streams.
Input and Output Chapter 3.5
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)

GetDirectory, GetFiles Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim currDir As String = "c:\" ListBox1.DataSource = Directory.GetDirectories(currDir) End Sub Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged ListBox2.DataSource = Directory.GetFiles(ListBox1.SelectedItem) End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim currDir As String = "c:\" ListBox1.DataSource = Directory.GetDirectories(currDir) End Sub Private Sub btnGetDir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetDir.Click ListBox1.DataSource = Directory.GetDirectories(ListBox1.SelectedItem) End Sub Private Sub btnGetFiles_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetFiles.Click ListBox2.DataSource = Directory.GetFiles(ListBox1.SelectedItem) End Sub Note: Number of subdirectories and files?

File Class Methods: –GetCreationTime (ByVal path As String) –GetLastAccessTime (ByVal path As String) –GetLastWriteTime (ByVal path As String) –GetAttributes (ByVal path As String) –Copy(ByVal sourceFileName As String, ByVal destFileName As String) –Delete(ByVal path As String) –Move(ByVal sourceFileName As String, ByVal destFileName As String)

Dim currDir As String = "c:\" Directory.SetCurrentDirectory(currDir) Dim fName 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

Example SMTP – folder: C:\inetpub\mailroot\drop List s in a listbox and display selected in a textbox.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim currDir As String = "c:\inetpub\mailroot\drop" ListBox1.DataSource = Directory.GetFiles(currDir) End Sub Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged Dim myFile As System.IO.StreamReader myFile = System.IO.File.OpenText(ListBox1.SelectedItem) TextBox1.Text = myFile.ReadToEnd() myFile.Close() End Sub