Results 1 to 4 of 4

Thread: Count all files in a directory tree including subdirectories in Windows XP

  1. #1
    Join Date
    Nov 2008
    Posts
    1,054

    Count all files in a directory tree including subdirectories in Windows XP

    Hello,

    I'm having trouble with is counting all the files in a directory (and subdorectoies), and excluding the directories themselves. I need your help on DOS batch program- DOS batch file to count number of files on a directory, directories and subdirectories and files within subdirectories or a quick and simple way to do the scanning through all subdirectories finding each file.

  2. #2
    Dr. V Guest

    Re: Count all files in a directory tree including subdirectories in Windows XP

    Xcopy is a command used on Microsoft Windows operating system for copying multiple files or entire directory trees from one directory to another and for copying files across a network. XCOPY has many different parameters that you can utilize. You can see a full list here.

  3. #3
    Join Date
    Apr 2008
    Posts
    3,267

    Re: Count all files in a directory tree including subdirectories in Windows XP

    You can use the DirectoryInfo and FileInfo Class to get all the Files.

    Here is a sample code to achieve this:

    Code:
    Code Snippet
    using System;
    
    using System.Collections.Generic;
    
    using System.Text;
    using System.IO;
    
     
    
    namespace GetAllFiles
    
    {
    
    class Program
    
    {
    
    static void Main(string[] args)
    
    {
    
    //Counter for the Number of Files
    
    int Count = 0;
    
     
    
    //Directory to be Searched
    
    string dir = @"C:\GetFiles";
    
    
    DirectoryInfo dirInfo = new DirectoryInfo(dir);
    
     
    
    //Get the Files in the Current Directory
    
    FileInfo[] fInfo = dirInfo.GetFiles();
    
    foreach (FileInfo f in fInfo)
    
    {
    
    Count++;
    
    Console.WriteLine(f.FullName);
    
    }
    
     
    
    
    //Get the Files in the SubDirectories
    
    Program p = new Program();
    
    p.GetDirFiles(dirInfo, ref Count);
    
     
    
    Console.WriteLine("Total Number of Files:" + Count);
    
    }
    
     
    
    private void GetDirFiles(DirectoryInfo dInfo, ref int Count)
    
    { 
    
    DirectoryInfo[] subDirInfo = dInfo.GetDirectories();
    
    foreach (DirectoryInfo sDir in subDirInfo)
    
    {
    
    FileInfo[] fSubInfo = sDir.GetFiles();
    
    foreach (FileInfo f in fSubInfo)
    
    {
    
    Count++;
    
    Console.WriteLine(f.FullName);
    
    }
    
    GetDirFiles(sDir,ref Count);
    
    } 
    
    }
    
    }
    
    }

    Hope it helps.

  4. #4
    Join Date
    Apr 2008
    Posts
    3,522

    Re: Count all files in a directory tree including subdirectories in Windows XP

    In order to view all of the directories and subdirectories on a hard drive, just type cd\ to the root of your drive and then the tree command is executed. Or else, only type the cd\subdirectories name and then the tree command is displayed.

Similar Threads

  1. Replies: 6
    Last Post: 25-02-2011, 10:40 AM
  2. How to shred entire directory (tree)
    By cHYNA in forum Operating Systems
    Replies: 3
    Last Post: 22-08-2010, 01:25 AM
  3. Counting all files in a directory (and subdirectories)
    By Sarasija in forum Operating Systems
    Replies: 4
    Last Post: 22-08-2010, 01:03 AM
  4. Listing the Files or Subdirectories in a Directory
    By Henryosa in forum Software Development
    Replies: 4
    Last Post: 26-02-2010, 06:39 PM
  5. How to Count nodes in Binary Tree ?
    By Harshini in forum Software Development
    Replies: 4
    Last Post: 23-04-2009, 10:54 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,913,671.77963 seconds with 16 queries