My knowledge of VB.net is limited (only have been reading from the book)
so what i need to do for my project is to populate a listbox with files from a certain directory (C:\folder)
then once it's populated, i can select an item and it will open up in a rich text box.
This is what i have so far for the active directory > list box: -
Dim di As New IO.DirectoryInfo("C:\Documents and Settings\user\Desktop\folder")
-
Dim diar1 As IO.FileInfo() = di.GetFiles()
-
Dim dra As IO.FileInfo
-
Dim files As String
-
-
'list the names of all files in the specified directory
-
For Each dra In diar1
-
Dim shortName As String
-
shortName = dra.Name.Replace("931pros-", "")
-
ListBox2.Items.Add(shortName)
-
Next
-
Thanks!
2 5831 - 'Create a form with a command button (command1), a list box (list1)
- 'and four text boxes (text1, text2, text3 and text4).
- 'Type in the first textbox a startingpath like c:\
- 'and in the second textbox you put a pattern like *.* or *.txt
-
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
-
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
-
Private Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
-
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
-
-
Const MAX_PATH = 260
-
Const MAXDWORD = &HFFFF
-
Const INVALID_HANDLE_VALUE = -1
-
Const FILE_ATTRIBUTE_ARCHIVE = &H20
-
Const FILE_ATTRIBUTE_DIRECTORY = &H10
-
Const FILE_ATTRIBUTE_HIDDEN = &H2
-
Const FILE_ATTRIBUTE_NORMAL = &H80
-
Const FILE_ATTRIBUTE_READONLY = &H1
-
Const FILE_ATTRIBUTE_SYSTEM = &H4
-
Const FILE_ATTRIBUTE_TEMPORARY = &H100
-
-
Private Type FILETIME
-
dwLowDateTime As Long
-
dwHighDateTime As Long
-
End Type
-
-
Private Type WIN32_FIND_DATA
-
dwFileAttributes As Long
-
ftCreationTime As FILETIME
-
ftLastAccessTime As FILETIME
-
ftLastWriteTime As FILETIME
-
nFileSizeHigh As Long
-
nFileSizeLow As Long
-
dwReserved0 As Long
-
dwReserved1 As Long
-
cFileName As String * MAX_PATH
-
cAlternate As String * 14
-
End Type
-
Function StripNulls(OriginalStr As String) As String
-
If (InStr(OriginalStr, Chr(0)) > 0) Then
-
OriginalStr = Left(OriginalStr, InStr(OriginalStr, Chr(0)) - 1)
-
End If
-
StripNulls = OriginalStr
-
End Function
-
-
Function FindFilesAPI(path As String, SearchStr As String, FileCount As Integer, DirCount As Integer)
-
Dim FileName As String ' Walking filename variable...
-
Dim DirName As String ' SubDirectory Name
-
Dim dirNames() As String ' Buffer for directory name entries
-
Dim nDir As Integer ' Number of directories in this path
-
Dim i As Integer ' For-loop counter...
-
Dim hSearch As Long ' Search Handle
-
Dim WFD As WIN32_FIND_DATA
-
Dim Cont As Integer
-
If Right(path, 1) <> "\" Then path = path & "\"
-
' Search for subdirectories.
-
nDir = 0
-
ReDim dirNames(nDir)
-
Cont = True
-
hSearch = FindFirstFile(path & "*", WFD)
-
If hSearch <> INVALID_HANDLE_VALUE Then
-
Do While Cont
-
DirName = StripNulls(WFD.cFileName)
-
' Ignore the current and encompassing directories.
-
If (DirName <> ".") And (DirName <> "..") Then
-
' Check for directory with bitwise comparison.
-
If GetFileAttributes(path & DirName) And FILE_ATTRIBUTE_DIRECTORY Then
-
dirNames(nDir) = DirName
-
DirCount = DirCount + 1
-
nDir = nDir + 1
-
ReDim Preserve dirNames(nDir)
-
End If
-
End If
-
Cont = FindNextFile(hSearch, WFD) 'Get next subdirectory.
-
Loop
-
Cont = FindClose(hSearch)
-
End If
-
' Walk through this directory and sum file sizes.
-
hSearch = FindFirstFile(path & SearchStr, WFD)
-
Cont = True
-
If hSearch <> INVALID_HANDLE_VALUE Then
-
While Cont
-
FileName = StripNulls(WFD.cFileName)
-
If (FileName <> ".") And (FileName <> "..") Then
-
FindFilesAPI = FindFilesAPI + (WFD.nFileSizeHigh * MAXDWORD) + WFD.nFileSizeLow
-
FileCount = FileCount + 1
-
List1.AddItem path & FileName
-
End If
-
Cont = FindNextFile(hSearch, WFD) ' Get next file
-
Wend
-
Cont = FindClose(hSearch)
-
End If
-
' If there are sub-directories...
-
If nDir > 0 Then
-
' Recursively walk into them...
-
For i = 0 To nDir - 1
-
FindFilesAPI = FindFilesAPI + FindFilesAPI(path & dirNames(i) & "\", SearchStr, FileCount, DirCount)
-
Next i
-
End If
-
End Function
-
Sub Command1_Click()
-
Dim SearchPath As String, FindStr As String
-
Dim FileSize As Long
-
Dim NumFiles As Integer, NumDirs As Integer
-
Screen.MousePointer = vbHourglass
-
List1.Clear
-
SearchPath = Text1.Text
-
FindStr = Text2.Text
-
FileSize = FindFilesAPI(SearchPath, FindStr, NumFiles, NumDirs)
-
Text3.Text = NumFiles & " Files found in " & NumDirs + 1 & " Directories"
-
Text4.Text = "Size of files found under " & SearchPath & " = " & Format(FileSize, "#,###,###,##0") & " Bytes"
-
Screen.MousePointer = vbDefault
-
End Sub
-
I think the above coding should work
Piyush
IT Engineer
<link removed>
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: jajoo |
last post by:
Hi everyone,
I am trying to send files with multipart/form-date. Everything is ok
with the send.
But when I am receiving the files I should specify a directory where
the files to be saved. The problem is that Tomcat saves the files into
%CATALINA_HOME%/bin directory. I am wondering why? Why not into my
application directory?
The application directory is %CATALINA_HOME%/webapps/picture.
As a parameter of directory I am giving "." – which...
|
by: Webmaster |
last post by:
Hi everyone...
I know this isn't strictly a php/mysql ng, but I was hoping maybe
someone here knows both languages and is willing to help.
I have a directory of text files that i'd like to import into a msql
table... I was wondering if there's an easier way to do this with
php/mysql, I'd like to avoid copy/pasting the entire directory
(thousands of files) into the database if i can.
|
by: Don |
last post by:
I intermittently get a runtime Compilation Error that says 'The
compiler failed with error code 2000'. It appears that a DLL cannot
be found in the 'temporary asp.net files' directory.
The Detailed Compiler Output is at the bottom of this post.
This is a custom dll named UtilitiesINGR.dll that I put in the GAC. I
added a machine.config entry to instruct my app to use the GAC entry.
Now I need to remove the dll from the GAC so I can...
|
by: SevenThugsSoftware |
last post by:
Does anyone know if there is a tool which can search a directory of
..dll files, for a particular namespace or object or method?
-Nesim
|
by: Stefan L |
last post by:
Hi NG,
I have a file driven application (a report server) which has to do some
work when new files arrive or are deleted.
When processing the notifications about newly created files from a
FileSystemWatcher I want to open the file and read some info from it.
Problem is that when opening the file directly when the event is fired I
usually get a "file used by another process".
| |
by: Kimera.Kimera |
last post by:
I'm trying to write a program in VB.net 2003 that basically deletes all
files, folders, sub-folders and sub-sub folders (etc).
The program is simply for deleting the Windows/Temp folder contents,
removing all the files/folders inside it.
The problem i am having is that i can only delete files in the
Windows/Temp folder, and i can't delete folders if they contain files,
i know that you can't do this.
|
by: ahammad |
last post by:
Hello,
I would like to scan a certain directory for XML files. Then I want to take in every XML file, read it, and stores the contents as a string in an array. For example, if the directory has file1.xml, file2.xml, and file3.xml, they would all be scanned and read. Then, all the contents of file1.xml would be stored in an array as the first element:
@array would contain the stuff in file1.xml
@array would contain the stuff in file2.xml...
|
by: shaiful |
last post by:
Hi all, I have a problem that "How to open files from any particaular directory?" I mean just I wanna to press button then autometically will open all files from directory one by one, Thanks in Advance
|
by: aboxylica |
last post by:
i know how to open a file and access its elements..now i have to open a folder containing these files and work with these files..
the normal open("directoryname") is giving me an error.
any suggestions??
looking for ur reply!
cheers!
|
by: paul86 |
last post by:
Hi all, I have a vb question that i'm hoping I can get some help with.
I have a directory of excel files (probably about 1000) of them. They are quote sheets for the company I work for, and they are all the exact same format. I need to create some code in vb using microsoft access that will scan through this directory of excel files, and pull certain cells of information from each of them, and store this information into an access database....
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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,...
|
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |