473,404 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Finding Files

HI everybody;

I have problem about selecting files in my main file. I have to find
the files whose ending INF. What Can I do?Can anybody help me?
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
public class FileClass
{
public static void Main(string[] args)
{
ReadFromFile("c:/a.txt");
}
static void ReadFromFile(string filename)
{
StreamReader SR;
string S;
SR = File.OpenText(filename);
S = SR.ReadLine();
while (S != null)
{
Console.WriteLine(S);
S = SR.ReadLine();
}
SR.Close();
}

}
}

Jul 3 '07 #1
6 1959
On Jul 3, 8:51 am, begum <begums...@gmail.comwrote:
I have problem about selecting files in my main file. I have to find
the files whose ending INF. What Can I do?Can anybody help me?
It's not at all clear what you're trying to do. Do you want to call
ReadFromFile for every .inf file in a particular directory? Or does
a.txt contain filenames?

Look at Directory.GetFiles for an easy way of finding files on the
file system.

Jon

Jul 3 '07 #2
On Jul 3, 11:15 am, "Jon Skeet [C# MVP]" <s...@pobox.comwrote:
On Jul 3, 8:51 am, begum <begums...@gmail.comwrote:
I have problem about selecting files in my main file. I have to find
the files whose ending INF. What Can I do?Can anybody help me?

It's not at all clear what you're trying to do. Do you want to call
ReadFromFile for every .inf file in a particular directory? Or does
a.txt contain filenames?

Look at Directory.GetFiles for an easy way of finding files on the
file system.

Jon


we have a main folder. and that folder has subfolders. we want to find
the .inf files in all subfolders.
Jul 3 '07 #3
On Jul 3, 9:23 am, begum <begums...@gmail.comwrote:
we have a main folder. and that folder has subfolders. we want to find
the .inf files in all subfolders.
In that case Directory.GetFiles is your friend - you can even ask it
to find recursively for you.

Jon

Jul 3 '07 #4
Yep, but only in .Net 1.1, otherwise he would have to write his own
recursive method. (Or search for the 1000 examples in the net)

"Jon Skeet [C# MVP]" wrote:
On Jul 3, 9:23 am, begum <begums...@gmail.comwrote:
we have a main folder. and that folder has subfolders. we want to find
the .inf files in all subfolders.

In that case Directory.GetFiles is your friend - you can even ask it
to find recursively for you.

Jon

Jul 3 '07 #5
On 3 jul, 03:51, begum <begums...@gmail.comwrote:
HI everybody;

I have problem about selecting files in my main file. I have to find
the files whose ending INF. What Can I do?Can anybody help me?
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
public class FileClass
{
public static void Main(string[] args)
{
ReadFromFile("c:/a.txt");
}
static void ReadFromFile(string filename)
{
StreamReader SR;
string S;
SR = File.OpenText(filename);
S = SR.ReadLine();
while (S != null)
{
Console.WriteLine(S);
S = SR.ReadLine();
}
SR.Close();
}

}

}


Jul 3 '07 #6
On 3 jul, 08:16, Martin# <Mar...@discussions.microsoft.comwrote:
Yep, but only in .Net 1.1, otherwise he would have to write his own
recursive method. (Or search for the 1000 examples in the net)
i think you refer to ones like this:

using System;
using System.Collection.Generic;
using System.IO;

public class Seeker
{

public static string[] RetrieveFilesFrom(string directory, string
searchPattern,int level)
{
List<stringfilenames = new List<string>();
Stack<stringdirectories = new Stack<string>()

directories.Push(directory);

while(directories.count!=0)
{
string currentDirectory = directoriesStack.Pop();

foreach(string file in
Directory.GetFiles(currentDirectory,searchPattern) )
filenames.Add(file);
if((level==-1) || (directories.count != level))
{
foreach(string subDirectory in
Directory.GetDirectories(currentDirectory))
directories.Push(subDirectory);
}

}
return filenames.ToArray();
}

}

public class Program
{

public static void Main(string[] args)
{
foreach(string path in RetrieveFilensFrom(@"C:\Program Files\",
"*.exe",-1)
Console.WriteLine(path);
Console.Read();
}

}

regards

horacio

Jul 3 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Tony Houghton | last post by:
I'm using pygame to write a game called Bombz which needs to save some data in a directory associated with it. In Unix/Linux I'd probably use "~/.bombz", in Windows something like "C:\Documents...
8
by: Kai-Mikael Jää-Aro | last post by:
AIUI, there are no global style defaults for HTML tags, i e the W3C does not enforce that e g an <H1> should have a specific type-face, size, and so on, but rather this is decided by the browser. ...
15
by: Benjamin Rutt | last post by:
Are there any C tools that can find redundant #includes in a project, so as to shorten compile time? Of course, eliminating single #includes by hand and determining if the recompile fails is one...
8
by: Rick Strahl [MVP] | last post by:
Hi all, I'm building an app that uses the ASP.Net runtime... One problem I've run into is that pages running inside of the runtime are not finding DLLs in the GAC. In fact, if I look at the...
9
by: Laurent Bugnion | last post by:
Hi, I am wondering what is the best way to find out which ASP.NET sessions are still active. Here is the reason: I have a custom control which can upload files. It saves the files in a folder...
1
by: me | last post by:
Hi, Im having a few issues with finding exactly which program may be accessing a certain file. Lets say I need to replace a DLL with a newer version, but I need to make sure its not being...
4
lucas911
by: lucas911 | last post by:
I'm sure that this is possible: I have a parent directory that has sub directories. Each sub directory will store certain files in certain formats, i.e. i have 1 directory for excel, 1 for...
1
by: avik1612 | last post by:
Hi, I have created a program to find text files in a particular directory or folder. and to find a particular word in that files i finding it difficult to put the list in an array and finding...
5
by: mohi | last post by:
hello everyone i m positing this again but can't help as im not finding any solution to this . my problem is i have to browse a directory to search for all the files in it and process certain...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.