Assembly : mscorlib (dans mscorlib.dll)
SyntaxePublic ReadOnly Property Length As Long
Dim instance As FileInfo Dim value As Long value = instance.Length
public long Length { get; }
public: property long long Length { long long get (); }
/** @property */
public long get_Length ()
public function get Length () : long
Valeur de la propriété
Taille du fichier en cours.
Exceptions| Type d'exception | Condition |
|---|---|
| Refresh ne peut pas mettre à jour l'état du fichier ou du répertoire. | |
| Le fichier n'existe pas. - ou - La propriété Length est appelée pour un répertoire. |
NotesLa valeur de cette propriété est référence Null (Nothing en Visual Basic) si le système de fichiers contenant le fichier ne prend pas en charge ces informations.
Le tableau suivant répertorie des exemples d'autres tâches d'E/S courantes ou apparentées.
| Pour effectuer cette opération... | Consultez l'exemple qui se trouve dans cette rubrique... |
|---|---|
| Créer un fichier texte. | |
| Écrire dans un fichier texte. | |
| Lire à partir d'un fichier texte. | |
| Ajouter du texte dans un fichier. | Comment : ouvrir un fichier journal et y ajouter des éléments |
| Copier un fichier. | |
| Renommer ou déplacer un fichier. | |
| Lire à partir d'un fichier binaire. | Comment : lire et écrire dans un fichier de données créé récemment |
| Écrire dans un fichier binaire. | Comment : lire et écrire dans un fichier de données créé récemment |
| Créer un sous-répertoire. | |
| Afficher les fichiers d'un répertoire. | |
| Trier les fichiers d'un répertoire par taille. | |
| Définir des attributs de fichier. |
ExempleL'exemple suivant affiche la taille des fichiers spécifiés.
' The following example displays the names and sizes ' of the files in the specified directory. Imports System Imports System.IO Public Class FileLength Public Shared Sub Main() ' Make a reference to a directory. Dim di As New DirectoryInfo("c:\") ' Get a reference to each file in that directory. Dim fiArr As FileInfo() = di.GetFiles() ' Display the names and sizes of the files. Dim f As FileInfo Console.WriteLine("The directory {0} contains the following files:", di.Name) For Each f In fiArr Console.WriteLine("The size of {0} is {1} bytes.", f.Name, f.Length) Next f End Sub 'Main End Class 'FileLength
// The following example displays the names and sizes // of the files in the specified directory. using System; using System.IO; public class FileLength { public static void Main() { // Make a reference to a directory. DirectoryInfo di = new DirectoryInfo("c:\\"); // Get a reference to each file in that directory. FileInfo[] fiArr = di.GetFiles(); // Display the names and sizes of the files. Console.WriteLine("The directory {0} contains the following files:", di.Name); foreach (FileInfo f in fiArr) Console.WriteLine("The size of {0} is {1} bytes.", f.Name, f.Length); } }
// The following example displays the names and sizes // of the files in the specified directory. using namespace System; using namespace System::IO; int main() { // Make a reference to a directory. DirectoryInfo^ di = gcnew DirectoryInfo( "c:\\" ); // Get a reference to each file in that directory. array<FileInfo^>^fiArr = di->GetFiles(); // Display the names and sizes of the files. Console::WriteLine( "The directory {0} contains the following files:", di->Name ); System::Collections::IEnumerator^ myEnum = fiArr->GetEnumerator(); while ( myEnum->MoveNext() ) { FileInfo^ f = safe_cast<FileInfo^>(myEnum->Current); Console::WriteLine( "The size of {0} is {1} bytes.", f->Name, f->Length ); } }
// The following example displays the names and sizes // of the files in the specified directory. import System.*; import System.IO.*; public class FileLength { public static void main(String[] args) { // Make a reference to a directory. DirectoryInfo di = new DirectoryInfo("c:\\"); // Get a reference to each file in that directory. FileInfo fiArr[] = di.GetFiles(); // Display the names and sizes of the files. Console.WriteLine("The directory {0} contains the following files:", di.get_Name()); for (int iCtr = 0; iCtr < fiArr.length; iCtr++) { FileInfo f = fiArr[iCtr]; Console.WriteLine("The size of {0} is {1} bytes.", f.get_Name(), System.Convert.ToString(f.get_Length())); } } //main } //FileLength
Plates-formesWindows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile pour Pocket PC, Windows Mobile pour Smartphone, Windows Server 2003, Windows XP Édition Media Center, Windows XP Professionnel Édition x64, Windows XP SP2, Windows XP Starter Edition
Le .NET Framework ne prend pas en charge toutes les versions de chaque plate-forme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise.
Informations de version
Outils (masquer)
S'enregistrer
Liste des Membres
Qui est en ligne?
FAQ