|
-
Feb 16th, 2004, 11:50 AM
#1
Thread Starter
Fanatic Member
Dir function
hi all,
in vb6, when i required list of all txt files in a directory, i used the following code:
VB Code:
DirArray(1) = Dir("c:\mydir\*.txt")
For ArrCnt = 2 To UBound(DirArray) - 1
DirArray(ArrCnt) = Dir() 'here's the problem with dir function
Next
but in vb.net, the dir function is not working without the pathname. in my xp pc, which is my development pc, no error is generated. but in client pc, which is win 98 se, it shows the error.
pls guide, what to do?
regards,
prakash
-
Feb 16th, 2004, 11:56 AM
#2
Sleep mode
Use the static Directory Class to get files with specific pattern .
VB Code:
Dim files() As String = IO.Directory.GetFiles("c:\", "*.txt")
For Each file As String In files
MessageBox.Show(file)
Next
-
Feb 16th, 2004, 01:05 PM
#3
Addicted Member
Hi,
Imports System
Imports System.IO
ListBox1.DataSource = Directory.GetFiles("C:\")
Have a nice day
-
Feb 17th, 2004, 02:01 AM
#4
Thread Starter
Fanatic Member
thanx for ur responses.
but just for info, anybody please tell me why the error was not thrown on xp pc, unlike win 98se.
regards
-
Feb 17th, 2004, 02:12 AM
#5
Sleep mode
What's the error message ?
-
Feb 19th, 2004, 05:09 AM
#6
Thread Starter
Fanatic Member
it gives some error that 'you cannot use dir() function without pathname.
-
Feb 19th, 2004, 06:29 AM
#7
Sleep mode
Originally posted by pvbangera
it gives some error that 'you cannot use dir() function without pathname.
Umm , you mean it complains if you provided a variable instead of pathname ? I'm afraid I couldn't get it .
-
Feb 25th, 2004, 03:09 AM
#8
Thread Starter
Fanatic Member
no, not like that. if i use dir() function without any arguments, then it shows error.
VB Code:
strPath = "c:\temp\*.txt"
strFile = dir(strPath) 'No problem
strFile = dir() 'Error occurs
regards
prakash
-
Feb 25th, 2004, 11:34 AM
#9
Sleep mode
Originally posted by pvbangera
VB Code:
strFile = dir() 'Error occurs
When you use it this way , what do you think dir() function would return ???????? .
You must specify path name .
-
Feb 26th, 2004, 01:29 AM
#10
Thread Starter
Fanatic Member
my dear friend,
i need not tell u that in vb6 when u say
it will return 1st txt file in the path and next time when u say
VB Code:
Text1 = dir() 'without any argument
it returns next txt file in the directory. i want to say that this is not working in vb.net.
i hope, i am clear.
-
Feb 26th, 2004, 01:34 AM
#11
Sleep mode
eeh , Do you really have to use that function (which is basically for compatibility code with VB6) . Have you checked IO.Directory.GetFiles() function ??
-
Feb 26th, 2004, 01:37 AM
#12
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Feb 26th, 2004, 01:43 AM
#13
Thread Starter
Fanatic Member
eeh (me too)
my purpose was solved by pirate's 1st post. but i had a question after that which i guess u ppl forgot.
but just for info, anybody please tell me why the error was not thrown on xp pc, unlike win 98se.
i dont want to use dir() function anymore. just for info sake i want the answer for the above question. thats all
-
Feb 26th, 2004, 01:44 AM
#14
Sleep mode
hehe , it's like plague over these forums . Could be VBF-Specific ?
-
Feb 26th, 2004, 01:49 AM
#15
Sleep mode
Originally posted by pvbangera
my purpose was solved by pirate's 1st post. but i had a question after that which i guess u ppl forgot.
i dont want to use dir() function anymore. just for info sake i want the answer for the above question. thats all
I don't know but it might be dumb enough if I say it has some issue with the OS and FS (NTFS vs FAT32) . I don't know what inside this function . I just check MSDN , and there's no note about supporting OS .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|