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

File types

ats
I am working on a program that will look in a folder and if it finds a
particular file type (i.e. a .TRN or a .BAK file), it will move the file to
another location. In VB 6 I was able to do this using a wildcard statement
like *.BAK or *.TRN. However, I cannot get this to work in VB.Net 2005. Can
anybody point me in the right direction for this please?

TIA

--
ats@jbex

No mercy for what we are doing
No thought to even what we have done
We don't need to feel the sorrow
No remorse for the helpless one

Metallica - No Remorse
Apr 17 '07 #1
4 1695
Ats,
Use DirectoryInfo.GetFiles, rather than Directory to get an array of
FileInfo objects, as the code below demonstrates.

Hope that helps.
Ralph Shillington
iFoundTIme Inc
http://www.ifoundtime.com/community
home of the coffee break tutorials.

Imports System.IO
Module Module1

Sub Main()

Dim files() As FileInfo = New DirectoryInfo("c:
\").GetFiles("*.txt")
For Each file As FileInfo In files
Console.WriteLine(file.FullName)
Next
End Sub

End Module

On Apr 17, 4:49 am, "ats@jbex" <a...@allenjones.NOSPAM.co.PLEASE.uk>
wrote:
I am working on a program that will look in a folder and if it finds a
particular file type (i.e. a .TRN or a .BAK file), it will move the file to
another location. In VB 6 I was able to do this using a wildcard statement
like *.BAK or *.TRN. However, I cannot get this to work in VB.Net 2005. Can
anybody point me in the right direction for this please?

TIA

--
ats@jbex

No mercy for what we are doing
No thought to even what we have done
We don't need to feel the sorrow
No remorse for the helpless one

Metallica - No Remorse

Apr 17 '07 #2
ats
On 17 Apr 2007 03:14:39 -0700, rshillington wrote:

Thanks for that, it does the trick. The problem I now have is that my
program creates a directory using the Directory.CreateDirectory(FullPath)
call. The directory is created but when I try to move a file into it I get
an error saying that I do not have permission to access the folder. If I
view the folder in Windows Explorer I can open it and move files into it.
Any ideas?

TIA
Ats,
Use DirectoryInfo.GetFiles, rather than Directory to get an array of
FileInfo objects, as the code below demonstrates.

Hope that helps.
Ralph Shillington
iFoundTIme Inc
http://www.ifoundtime.com/community
home of the coffee break tutorials.

Imports System.IO
Module Module1

Sub Main()

Dim files() As FileInfo = New DirectoryInfo("c:
\").GetFiles("*.txt")
For Each file As FileInfo In files
Console.WriteLine(file.FullName)
Next
End Sub

End Module

On Apr 17, 4:49 am, "ats@jbex" <a...@allenjones.NOSPAM.co.PLEASE.uk>
wrote:
>I am working on a program that will look in a folder and if it finds a
particular file type (i.e. a .TRN or a .BAK file), it will move the file to
another location. In VB 6 I was able to do this using a wildcard statement
like *.BAK or *.TRN. However, I cannot get this to work in VB.Net 2005. Can
anybody point me in the right direction for this please?

TIA

--
ats@jbex

No mercy for what we are doing
No thought to even what we have done
We don't need to feel the sorrow
No remorse for the helpless one

Metallica - No Remorse

--
ats@jbex

But I learned to burn that bridge and delete
Those who compete...at a level that's obsolete
Instead I warm my hands upon the flames of the flag
As I recall our downfall
And the business that burned us all
See through the news and the views that twist reality

Rage Against The Machine - Bombtrack
Apr 17 '07 #3

hmmm --- Do you perhaps have the file open that you're trying to
move? Could you post a snippet of the code the reproduces the
problem? How you create the directory shouldn't matter.

Ralph Shillington
iFoundTIme Inc
http://www.ifoundtime.com/community
home of the coffee break tutorials.


On Apr 17, 7:43 am, "ats@jbex" <a...@allenjones.NOSPAM.co.PLEASE.uk>
wrote:
On 17 Apr 2007 03:14:39 -0700, rshillington wrote:

Thanks for that, it does the trick. The problem I now have is that my
program creates a directory using the Directory.CreateDirectory(FullPath)
call. The directory is created but when I try to move a file into it I get
an error saying that I do not have permission to access the folder. If I
view the folder in Windows Explorer I can open it and move files into it.
Any ideas?

TIA


Ats,
Use DirectoryInfo.GetFiles, rather than Directory to get an array of
FileInfo objects, as the code below demonstrates.
Hope that helps.
Ralph Shillington
iFoundTIme Inc
http://www.ifoundtime.com/community
home of the coffee break tutorials.
Imports System.IO
Module Module1
Sub Main()
Dim files() As FileInfo = New DirectoryInfo("c:
\").GetFiles("*.txt")
For Each file As FileInfo In files
Console.WriteLine(file.FullName)
Next
End Sub
End Module
On Apr 17, 4:49 am, "ats@jbex" <a...@allenjones.NOSPAM.co.PLEASE.uk>
wrote:
I am working on a program that will look in a folder and if it finds a
particular file type (i.e. a .TRN or a .BAK file), it will move the file to
another location. In VB 6 I was able to do this using a wildcard statement
like *.BAK or *.TRN. However, I cannot get this to work in VB.Net 2005. Can
anybody point me in the right direction for this please?
TIA
--
ats@jbex
No mercy for what we are doing
No thought to even what we have done
We don't need to feel the sorrow
No remorse for the helpless one
Metallica - No Remorse

--
ats@jbex

But I learned to burn that bridge and delete
Those who compete...at a level that's obsolete
Instead I warm my hands upon the flames of the flag
As I recall our downfall
And the business that burned us all
See through the news and the views that twist reality

Rage Against The Machine - Bombtrack- Hide quoted text -

- Show quoted text -

Apr 18 '07 #4
ats
On 18 Apr 2007 06:46:24 -0700, rshillington wrote:

Hi there,
Thanks for the reply. The file is definitely not open when I try to move
it. The code I use is here:

Sub MoveData()

Dim f As String = ""
Dim d As Date = DateAdd(DateInterval.Day, -1, Date.Today)

Me.Label1.Text = "Creating Directory"

f = "F:\DataBackup" & Format(d, "yyyymmdd")

Directory.CreateDirectory(f)

Me.Label1.Text = "Moving Backup Transaction Logs"

Dim filesTRN() As FileInfo = New
DirectoryInfo("G:\").GetFiles("*.TRN")
For Each file As FileInfo In filesTRN
file.MoveTo(f)
Next

Me.Label1.Text = "Moving Backup DB Files"

Dim filesBAK() As FileInfo = New
DirectoryInfo("G:\").GetFiles("*.BAK")
For Each file As FileInfo In filesBAK
file.MoveTo(f)
Next

End Sub

Thanks again.
hmmm --- Do you perhaps have the file open that you're trying to
move? Could you post a snippet of the code the reproduces the
problem? How you create the directory shouldn't matter.

Ralph Shillington
iFoundTIme Inc
http://www.ifoundtime.com/community
home of the coffee break tutorials.
--
ats@jbex

The world is my expense
The cost of my desire
Jesus blessed me with its future
And I protect it with fire

Rage Against The Machine - Sleep Now In The Fire
Apr 18 '07 #5

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

Similar topics

0
by: Phil Powell | last post by:
// PROCESS XML CONTENT INTO DYNAMICALLY-NAMED ARRAYS foreach (array('mime', 'state', 'country') as $val) { $parser = xml_parser_create(); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);...
19
by: Mel | last post by:
when downloading files from my site, when file types are known (i.e *.doc) browsers open the file for viewing. is there a way to disable that and just present the save as dialog (same as for...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
6
by: JD | last post by:
Hi all, Can anyone tell me is there a way to get a list of file types either supported on the server or clients computer and bind it to a drop down list in C# Thanks Jonathan Dixon
2
by: Manny Chohan | last post by:
Guys, I am giving users to upload files on my server. i have Symantec virus scan on my server running in the background. Now would a user be able to upload document with virus inside it or not...
3
by: Shapper | last post by:
Hello, I created a script to upload a file. To determine the file type I am using userPostedFile.ContentType. For example, for a png image I get "image/png". My questions are: 1. Where can...
5
by: Seok Bee | last post by:
Dear Experts, I currently trying to use the FileUpload control from asp.net 2.0 to upload files. The uploading of the file I would like to store it in the Access Database. Unfortunately, I've no...
11
by: mesut demir | last post by:
Hi All, When I create fields (in files) I need assign a data type like char, varchar, money etc. I have some questions about the data types when you create fields in a file. What is the...
1
by: iwdu15 | last post by:
hi, how can i get the icon associated with a certain file type? thanks -- -iwdu15
0
by: Hags007 | last post by:
I have a XML file I am working with. This file has been created by hand and I now need to develop a PHP script that will create it in the same format. Here is what I have thus far: $query =...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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.