954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Scanning of files

Hi,
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.... :-)
Thanks
Regards

GermanD
Newbie Poster
8 posts since Jan 2006
Reputation Points: 10
Solved Threads: 0
 

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

f1 fan
Posting Whiz in Training
279 posts since Jan 2006
Reputation Points: 26
Solved Threads: 11
 

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

GermanD
Newbie Poster
8 posts since Jan 2006
Reputation Points: 10
Solved Threads: 0
 

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()
        {
            InitializeComponent();
            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)
                {
                    MessageBox.Show(fileName);
                }

                // 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) !=
                             FileAttributes.ReparsePoint)

                        scanDir(subdir, recursionLvl + 1);
            }
        }
    }
}


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

tayspen
<Insert title here>
Team Colleague
1,622 posts since Jul 2005
Reputation Points: 84
Solved Threads: 99
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You