Visual Basic | Working with files 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.

Software ==> Visual Basic  (46 exercises)
Version ==> Any version of VB
Topic ==> Working with files  (3 exercises)
Level ==> Harder than average
Subject ==> Visual Basic training

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).



  • 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).

You can unzip this file to see the answers to this exercise, although please remember this is for your personal use only.
This page has 0 threads Add post