Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
551 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Software ==> | SSIS Integration Services (28 exercises) |
Topic ==> | Accessing file attributes (2 exercises) |
Level ==> | Harder than average |
Subject ==> | SSIS training |
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 above folder has 4 files in:
The four files in the above folder. Your task is to add the file sizes together, and report back!
If you right-click on the files to show their properties, you should see this:
The total size for all of the files is 210,304 bytes - something we intend to prove with an SSIS package!
To start, create a new package called File Sizes, and add the following variables to it:
We'll use the first variable to accumulate the total file size (set it to 0) and the second one to hold the file name/path for each file in turn.
Create a Foreach Loop container to loop over the files in the above folder, calling a script task for each:
Remember to assign your FilePath variable to the Foreach Loop container, to tell SSIS where each file name/path will be stored.
Assign your variables to the script task:
The script will need to read each variable's file path (so this is read-only), but will need to add to the cumulative size (so this is read-write).
In the script for the script task, remember to reference the files and folders namespace:
// reference namespace
using System.IO;
Now write the script to get a pointer to the file whose name and path are stored in the FilePath variable, get the size of this file (using its Length property) and add this to the CumulativeSize read/write variable. Here are a couple of lines your code could include:
// get a reference to this file
var thisFile = new FileInfo(thisFilePath);
// get the size of this file
long fileSize = thisFile.Length;
When you've finished, add another script task to report what you've found:
The final script task should display the total file size accumulated in the variable.
Here's what your package should show when you run it:
Yeah - the correct result!
Close your package down, reflecting on how you might use this in "real" life.
You can find other training resources for the subject of this exercise here:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2024. All Rights Reserved.