473,800 Members | 3,056 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to filter by File Type ?

Rob
I want to copy files from one folder to another... but only if it is a
".txt" file...

Below should work, but how would you filter on ".txt" files only ?

Thanks !

Dim fileEntries As String() = Directory.GetFi les(targetDirec tory)
' Process the list of files found in the directory.
Dim fileName As String
For Each fileName In fileEntries
' Do the File.copy here

Next fileName
Jun 27 '06 #1
6 1484
Rob,

Directory.GetFi les has an overloaded version that lets you specify the
search criteria, such as "*.txt".

Kerry Moorman
"Rob" wrote:
I want to copy files from one folder to another... but only if it is a
".txt" file...

Below should work, but how would you filter on ".txt" files only ?

Thanks !

Dim fileEntries As String() = Directory.GetFi les(targetDirec tory)
' Process the list of files found in the directory.
Dim fileName As String
For Each fileName In fileEntries
' Do the File.copy here

Next fileName

Jun 27 '06 #2
Rob
The code below is returning the complete path of the file as well as the
filename.... Any way to return only the filename without the path ?

Dim fileEntries As String() = Directory.GetFi les(targetDirec tory)
' Process the list of files found in the directory.
Dim fileName As String
For Each fileName In fileEntries
' Do the File.copy here

Next fileName

"Kerry Moorman" <Ke**********@d iscussions.micr osoft.com> wrote in message
news:66******** *************** ***********@mic rosoft.com...
Rob,

Directory.GetFi les has an overloaded version that lets you specify the
search criteria, such as "*.txt".

Kerry Moorman
"Rob" wrote:
I want to copy files from one folder to another... but only if it is a
".txt" file...

Below should work, but how would you filter on ".txt" files only ?

Thanks !

Dim fileEntries As String() = Directory.GetFi les(targetDirec tory)
' Process the list of files found in the directory.
Dim fileName As String
For Each fileName In fileEntries
' Do the File.copy here

Next fileName

Jun 27 '06 #3
Rob,

You could use the Path class's GetFileName method.

Kerry Moorman
"Rob" wrote:
The code below is returning the complete path of the file as well as the
filename.... Any way to return only the filename without the path ?

Dim fileEntries As String() = Directory.GetFi les(targetDirec tory)
' Process the list of files found in the directory.
Dim fileName As String
For Each fileName In fileEntries
' Do the File.copy here

Next fileName

"Kerry Moorman" <Ke**********@d iscussions.micr osoft.com> wrote in message
news:66******** *************** ***********@mic rosoft.com...
Rob,

Directory.GetFi les has an overloaded version that lets you specify the
search criteria, such as "*.txt".

Kerry Moorman
"Rob" wrote:
I want to copy files from one folder to another... but only if it is a
".txt" file...

Below should work, but how would you filter on ".txt" files only ?

Thanks !

Dim fileEntries As String() = Directory.GetFi les(targetDirec tory)
' Process the list of files found in the directory.
Dim fileName As String
For Each fileName In fileEntries
' Do the File.copy here

Next fileName


Jun 27 '06 #4
Rob
Kerry,

Almost there... just one more piece... the line with leading ***** below
filtering on ".txt" in a loop ?

Thanks,
Rob

Dim fileEntries As String() = Directory.GetFi les(strEODFolde rSrc)

Dim fSource As String

Dim fDest As String

' Process the list of files found in the directory.

Dim fileName As String

For Each fileName In fileEntries

fSource = strEODFolderSrc & Path.GetFileNam e(fileName)

fDest = strEODFolderDes t & Path.GetFileNam e(fileName)

' Only show text files ????

'******** If the file extention of Path.GetFileNam e(fileName) Then

MsgBox("Source: " & fSource)

MsgBox("Dest:" & fDest)

End If

Next fileName

"Kerry Moorman" <Ke**********@d iscussions.micr osoft.com> wrote in message
news:D6******** *************** ***********@mic rosoft.com...
Rob,

You could use the Path class's GetFileName method.

Kerry Moorman
"Rob" wrote:
The code below is returning the complete path of the file as well as the
filename.... Any way to return only the filename without the path ?

Dim fileEntries As String() = Directory.GetFi les(targetDirec tory)
' Process the list of files found in the directory.
Dim fileName As String
For Each fileName In fileEntries
' Do the File.copy here

Next fileName

"Kerry Moorman" <Ke**********@d iscussions.micr osoft.com> wrote in message
news:66******** *************** ***********@mic rosoft.com...
> Rob,
>
> Directory.GetFi les has an overloaded version that lets you specify the
> search criteria, such as "*.txt".
>
> Kerry Moorman
>
>
> "Rob" wrote:
>
>> I want to copy files from one folder to another... but only if it is a
>> ".txt" file...
>>
>> Below should work, but how would you filter on ".txt" files only ?
>>
>> Thanks !
>>
>> Dim fileEntries As String() = Directory.GetFi les(targetDirec tory)
>> ' Process the list of files found in the directory.
>> Dim fileName As String
>> For Each fileName In fileEntries
>> ' Do the File.copy here
>>
>> Next fileName
>>
>>
>>


Jun 27 '06 #5
Rob,

You could use Path.GetExtensi on (fileName) to get the file's extension.

But as I mentioned in my first reply, you could also use:

Dim fileEntries As String() = Directory.GetFi les(strEODFolde rSrc, "*.txt")

to just retrieve and process files with a ".txt" extension.

Kerry Moorman
"Rob" wrote:
Kerry,

Almost there... just one more piece... the line with leading ***** below
filtering on ".txt" in a loop ?

Thanks,
Rob

Dim fileEntries As String() = Directory.GetFi les(strEODFolde rSrc)

Dim fSource As String

Dim fDest As String

' Process the list of files found in the directory.

Dim fileName As String

For Each fileName In fileEntries

fSource = strEODFolderSrc & Path.GetFileNam e(fileName)

fDest = strEODFolderDes t & Path.GetFileNam e(fileName)

' Only show text files ????

'******** If the file extention of Path.GetFileNam e(fileName) Then

MsgBox("Source: " & fSource)

MsgBox("Dest:" & fDest)

End If

Next fileName

"Kerry Moorman" <Ke**********@d iscussions.micr osoft.com> wrote in message
news:D6******** *************** ***********@mic rosoft.com...
Rob,

You could use the Path class's GetFileName method.

Kerry Moorman
"Rob" wrote:
The code below is returning the complete path of the file as well as the
filename.... Any way to return only the filename without the path ?

Dim fileEntries As String() = Directory.GetFi les(targetDirec tory)
' Process the list of files found in the directory.
Dim fileName As String
For Each fileName In fileEntries
' Do the File.copy here

Next fileName

"Kerry Moorman" <Ke**********@d iscussions.micr osoft.com> wrote in message
news:66******** *************** ***********@mic rosoft.com...
> Rob,
>
> Directory.GetFi les has an overloaded version that lets you specify the
> search criteria, such as "*.txt".
>
> Kerry Moorman
>
>
> "Rob" wrote:
>
>> I want to copy files from one folder to another... but only if it is a
>> ".txt" file...
>>
>> Below should work, but how would you filter on ".txt" files only ?
>>
>> Thanks !
>>
>> Dim fileEntries As String() = Directory.GetFi les(targetDirec tory)
>> ' Process the list of files found in the directory.
>> Dim fileName As String
>> For Each fileName In fileEntries
>> ' Do the File.copy here
>>
>> Next fileName
>>
>>
>>


Jun 27 '06 #6
Rob
Thanks very much Kerry !
"Kerry Moorman" <Ke**********@d iscussions.micr osoft.com> wrote in message
news:5C******** *************** ***********@mic rosoft.com...
Rob,

You could use Path.GetExtensi on (fileName) to get the file's extension.

But as I mentioned in my first reply, you could also use:

Dim fileEntries As String() = Directory.GetFi les(strEODFolde rSrc,
"*.txt")

to just retrieve and process files with a ".txt" extension.

Kerry Moorman
"Rob" wrote:
Kerry,

Almost there... just one more piece... the line with leading ***** below
filtering on ".txt" in a loop ?

Thanks,
Rob

Dim fileEntries As String() = Directory.GetFi les(strEODFolde rSrc)

Dim fSource As String

Dim fDest As String

' Process the list of files found in the directory.

Dim fileName As String

For Each fileName In fileEntries

fSource = strEODFolderSrc & Path.GetFileNam e(fileName)

fDest = strEODFolderDes t & Path.GetFileNam e(fileName)

' Only show text files ????

'******** If the file extention of Path.GetFileNam e(fileName) Then

MsgBox("Source: " & fSource)

MsgBox("Dest:" & fDest)

End If

Next fileName

"Kerry Moorman" <Ke**********@d iscussions.micr osoft.com> wrote in message
news:D6******** *************** ***********@mic rosoft.com...
> Rob,
>
> You could use the Path class's GetFileName method.
>
> Kerry Moorman
>
>
> "Rob" wrote:
>
>> The code below is returning the complete path of the file as well as
>> the
>> filename.... Any way to return only the filename without the path ?
>>
>> Dim fileEntries As String() = Directory.GetFi les(targetDirec tory)
>> ' Process the list of files found in the directory.
>> Dim fileName As String
>> For Each fileName In fileEntries
>> ' Do the File.copy here
>>
>> Next fileName
>>
>>
>>
>> "Kerry Moorman" <Ke**********@d iscussions.micr osoft.com> wrote in
>> message
>> news:66******** *************** ***********@mic rosoft.com...
>> > Rob,
>> >
>> > Directory.GetFi les has an overloaded version that lets you specify
>> > the
>> > search criteria, such as "*.txt".
>> >
>> > Kerry Moorman
>> >
>> >
>> > "Rob" wrote:
>> >
>> >> I want to copy files from one folder to another... but only if it
>> >> is a
>> >> ".txt" file...
>> >>
>> >> Below should work, but how would you filter on ".txt" files only ?
>> >>
>> >> Thanks !
>> >>
>> >> Dim fileEntries As String() = Directory.GetFi les(targetDirec tory)
>> >> ' Process the list of files found in the directory.
>> >> Dim fileName As String
>> >> For Each fileName In fileEntries
>> >> ' Do the File.copy here
>> >>
>> >> Next fileName
>> >>
>> >>
>> >>
>>
>>
>>


Jun 27 '06 #7

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

Similar topics

9
12242
by: Robin Cull | last post by:
Imagine I have a dict looking something like this: myDict = {"key 1": , "key 2": , "key 3": , "key 4": } That is, a set of keys which have a variable length list of associated values after them. What I want to do is filter out a subset of this dict to produce another dict that satisfies a set of criteria (in this case whether it contains all four values) to end up with something
1
4432
by: soupaman | last post by:
Im trying to output some filtered xml using the xmlTextReader I know the code and commenting needs cleaned up and eventually plan to add the values to a dataset. currently what this is doing is matching the filters, runs into the response.write and outputs nothing. I've used the dbgclr to verify that the filters are matching and it is hitting the response.write what I want it to do is match the filters (an array) and output the value of...
0
6476
by: CSDunn | last post by:
Hello, I have a problem with field filtering between an Access 2000 Project form (the application is called CELDT), and the report that shows the results of the filter. Both the form and the report are based on the same View addressed in the Record Source of both as 'dbo.CLMain_vw'. The View resides in a SQL Server 2000 database. There are two different problems I am having with filtering: The first involves filtering in the form by date...
8
6100
by: marcus.kwok | last post by:
I am having a weird problem and I have can't figure out why it is happening. I create an OpenFileDialog and set a filename filter. When the dialog first opens, the filter works correctly, and only the files I want to see appear in the file list box. When I change the filter to one of the other filters, all the files in the list disappear. If I then manually type a filter into the "Filename" textbox, then the files appear and the filter...
2
1269
by: Jeff Calico | last post by:
Hello everyone I have sucessfully implemented a SAX filter to take a large XML data file, and strip it down to its essential elements, and then pass that on to an XSL transformer. (A bare bones example of the java code is listed at the end) I also need another XML file, a list of all possible records, which I use for getting additional information by cross referencing with xsl:key. The list file only has one type of element, and I...
0
9550
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
10269
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
10248
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
10032
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...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7573
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
6811
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
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4148
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.