Member Avatar

Could you maybe help me out with some code to scan folders and subfolders for files?PLEASE...
I cant find any useful information on the net..
All i wanna do is search a selected folder with its subfolders for a specific file types and then rename those found files extension to for example .rar files...
Any help would be greatly appreciated.... :-)

Use the Directory, DirectoryInfo, File and FileInfo classes in the System.IO namespace

Member Avatar

wow thanks now that helps...i know i have to use that but i dont know how...anyway il try to find a different forum for help not that there really are any...

Hi, is this what you want, I threw it together real quick, but you should be able to finish the rest, this will get you started.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace filetest
    public partial class Form1 : Form
        public Form1()
            scanDir("C:\\", 1);

        const int HowDeepToScan = 7;

        private static void prcoessdire(string sourceDir, int recursionLvl)
            scanDir(sourceDir, recursionLvl);

        private static void scanDir(string sourceDir, int recursionLvl)
            if (recursionLvl <= HowDeepToScan)
                // Process the list of files found in the directory.
                string[] fileEntries = Directory.GetFiles(sourceDir);
                foreach (string fileName in fileEntries)

                // Recurse into subdirectories of this directory.
                string[] subdirEntries = Directory.GetDirectories(sourceDir);
                foreach (string subdir in subdirEntries)
                    // Do not iterate through reparse points
                    if ((File.GetAttributes(subdir) &
                         FileAttributes.ReparsePoint) !=

                        scanDir(subdir, recursionLvl + 1);

This is just the basic concet of it....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.