Exercise: Find the largest file by size in a folder

This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.

The answer to the exercise will be included and explained if you attend the Wise Owl course listed below!

Category ==> Visual Basic 2010  (42 exercises)
Topic ==> Working with files  (3 exercises)
Level ==> Harder than average
Course ==> Introduction to VB.NET

You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Create a new form, and in this create a single button.  Attach code to this button so that when you click on it you see a message giving the name and size of the largest file in a given folder:

Results of search

The sort of thing you should see when you run your program (see the notes below).

 

Notes:

  • You can include the file path in your code as a constant.
  • To look at the size of a file, use its Length property.

If you've got that working, try making the program recursive (so that it calls itself to search through not just the folder given, but also all of its subfolders).

This page has 0 threads Add post