473,385 Members | 1,630 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,385 software developers and data experts.

How to Retrieve all file names and write to TextFile

126 100+
Hi Good Guys,
I need your help. Please help me.

My office BA requested me to develop Window application to retrieve all the files from the SalesDepartment folder : F:\SalesDept and write the name of the file into a TextFile and save it into this folder F:\StoreFileName\

I have not written this type of coding before and I need your help to show me sample coding in order for me to learn something new.

Thank You,

Cheers,
Lennie
Sep 26 '10 #1

✓ answered by Subin Ninan

This is how you can do it in C#.

Expand|Select|Wrap|Line Numbers
  1. FileStream fs = new FileStream(@"F:\StoreFileName\FileList.txt", FileMode.Create, FileAccess.Write);
  2. StreamWriter writer = new StreamWriter(fs);
  3. foreach (string file in Directory.GetFiles(@"F:\SalesDept"))
  4. {
  5.    writer.WriteLine(file.ToString());
  6. }
  7. writer.Close();
  8. fs.Close();
  9.  

2 1573
This is how you can do it in C#.

Expand|Select|Wrap|Line Numbers
  1. FileStream fs = new FileStream(@"F:\StoreFileName\FileList.txt", FileMode.Create, FileAccess.Write);
  2. StreamWriter writer = new StreamWriter(fs);
  3. foreach (string file in Directory.GetFiles(@"F:\SalesDept"))
  4. {
  5.    writer.WriteLine(file.ToString());
  6. }
  7. writer.Close();
  8. fs.Close();
  9.  
Sep 26 '10 #2
lenniekuah
126 100+
Hullo Subin Ninan,

What the Project Reference file name ?

Thank you very much for helping with the sample coding. You are awesome, wonderful and very helpful. I will learn this logical technology by trying it out. I will get back to you after putting it on my application.

I will post the working coding here to share with other Newbies who may have similar problem in appreciation of your help.

Thank you and Have a Good Day.

Cheers,
Lennie
Sep 26 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Simon Wigzell | last post by:
I recently wrote a program with MS Visual Studio C++, sent it off to the client where it didn't run, after some probing I discover they are on a Mac! My program is a MSF interface that is really...
3
by: Chris | last post by:
Hi, In C# I tried to save a file from a generated file name. Just before launching the dialog I check for a valid file name to be sure. There for I used the method ValidateNames from the save...
5
by: johnwayne83 | last post by:
This is my first semester in c++ and i took java last semester. I need some help and i really cant find any information that has helped me or to point me in the right direction. I am using...
0
by: chongming | last post by:
Hi, i want to display all the filenames on browser. However i found that if there are many filenames in that folder, result will be it will display a long list of filenames on that browser. My...
0
by: stainless | last post by:
I know this is not necessarily a C# question but the code I am wrinting is C# and I wasn't sure whereelse to ask the question. I have taken some web code (from codeproject.com) that performs FTP...
3
by: =?ISO-2022-JP?B?Ik1hcnRpbiB2LiBMbyJ3aXMi?= | last post by:
Step 4: Either wait for Python 2.7 or apply the patch to your own copy Actually, this is released in Python 2.6, see r62724. Regards, Martin
1
by: mujunshan | last post by:
Yesterday, I installed PythonCE on my cellphone whose OS is Windows Mobile 5.I wanted to use numpy as calculation tool.But after I copy numpy module in my desktop computer into my phone,I find many...
7
Frinavale
by: Frinavale | last post by:
Is there a way to dynamically retrieve the names of the public methods for an Object?
1
by: Ormazd | last post by:
Hello, I was wondering if anyone might be able to help me with a little PERL script? I'm very new and I have been given a task to write a simple Perl script that prints out the file names and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.