File types

A

ats@jbex

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
 
R

rshillington

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
 
A

ats@jbex

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


--
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
 
R

rshillington

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.
 
A

ats@jbex

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

MSgBox in VB.Net 2005 3
XML 2
Dates 3
Form to XML 2
Email Archive program 12
POST xml and read response 2
XML and POST 4
Documents 1

Top