Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / April 2007

Tip: Looking for answers? Try searching our database.

File types

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ats@jbex - 17 Apr 2007 09:49 GMT
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

Signature

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

rshillington - 17 Apr 2007 11:14 GMT
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
[quoted text clipped - 13 lines]
>
> Metallica - No Remorse
ats@jbex - 17 Apr 2007 12:43 GMT
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
[quoted text clipped - 39 lines]
>>
>> Metallica - No Remorse

Signature

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

rshillington - 18 Apr 2007 14:46 GMT
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:

> Thanks for that, it does the trick. The problem I now have is that my
> program creates a directory using the Directory.CreateDirectory(FullPath)
[quoted text clipped - 62 lines]
>
> - Show quoted text -
ats@jbex - 18 Apr 2007 15:08 GMT
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
[quoted text clipped - 4 lines]
> http://www.ifoundtime.com/community
> home of the coffee break tutorials.

Signature

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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.