473,791 Members | 3,097 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Collecti ons.Generic;
using System.Text;
using System.IO;

namespace ConsoleApplicat ion1
{
public class FileClass
{
public static void Main(string[] args)
{
ReadFromFile("c :/a.txt");
}
static void ReadFromFile(st ring filename)
{
StreamReader SR;
string S;
SR = File.OpenText(f ilename);
S = SR.ReadLine();
while (S != null)
{
Console.WriteLi ne(S);
S = SR.ReadLine();
}
SR.Close();
}

}
}

Jul 3 '07 #1
6 1980
On Jul 3, 8:51 am, begum <begums...@gmai l.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.GetFi les 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.com wrote:
On Jul 3, 8:51 am, begum <begums...@gmai l.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.GetFi les 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...@gmai l.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.GetFi les 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...@gmai l.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.GetFi les 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...@gmai l.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.Collecti ons.Generic;
using System.Text;
using System.IO;

namespace ConsoleApplicat ion1
{
public class FileClass
{
public static void Main(string[] args)
{
ReadFromFile("c :/a.txt");
}
static void ReadFromFile(st ring filename)
{
StreamReader SR;
string S;
SR = File.OpenText(f ilename);
S = SR.ReadLine();
while (S != null)
{
Console.WriteLi ne(S);
S = SR.ReadLine();
}
SR.Close();
}

}

}


Jul 3 '07 #6
On 3 jul, 08:16, Martin# <Mar...@discuss ions.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.Collecti on.Generic;
using System.IO;

public class Seeker
{

public static string[] RetrieveFilesFr om(string directory, string
searchPattern,i nt level)
{
List<stringfile names = new List<string>();
Stack<stringdir ectories = new Stack<string>()

directories.Pus h(directory);

while(directori es.count!=0)
{
string currentDirector y = directoriesStac k.Pop();

foreach(string file in
Directory.GetFi les(currentDire ctory,searchPat tern))
filenames.Add(f ile);
if((level==-1) || (directories.co unt != level))
{
foreach(string subDirectory in
Directory.GetDi rectories(curre ntDirectory))
directories.Pus h(subDirectory) ;
}

}
return filenames.ToArr ay();
}

}

public class Program
{

public static void Main(string[] args)
{
foreach(string path in RetrieveFilensF rom(@"C:\Progra m Files\",
"*.exe",-1)
Console.WriteLi ne(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
2690
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 And Settings\<user>\Applicacation Data\Bombz". There are plenty of messages in the archives for this group about how to find the correct location in Windows, but what about Mac OS? There I don't know the correct location for this sort of thing at...
8
4816
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. Is there any way of finding out what the default style settings of a given browser is?
15
2779
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 option, though that is an extremely manual and time-intensive approach. Thanks, -- Benjamin
8
2015
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 debug trace of the search path it searches the bin directory and Temporary ASP files but not the GAC. A simple example I used was trying to load System.Windows.Forms. If I add a
9
2309
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 named after the SessionID. At Session_End, I do some cleanup and delete the "session folder". However, if the PC is rebooted before the session times out, the clean up never happens. So what I wanted to do isL: In my CleanUp method, check all...
1
7541
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 accessed. Finding out if its in use isnt a problem, but I need to find out exactly which process is using it so I can ask the user if they would like to end that process to replace the file or not.
4
1917
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 word... and so on. As an example i have a sub directory called FinalDocumentation that will store excel files based on my final documentation template. Every file will have the same convention i.e. TXX_08-Mar-2007_Final_Documentation_Joe_Smith.xls...
1
1362
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 the words I have pasted the code below
5
4485
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 files with some extensions like .txt, .doc etc ..but i dont know about the actual file names only extension is know as "utab" suggested me to look at boost::filesystem i tried there also but cudn't get something which can solve this problem...
0
9669
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9515
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10207
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10155
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9995
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.