![]() |
Click here to advertise with us
|
|
|||||||
| Windows Forms Discussion related to Winforms application development |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
I'm currently working on an application that allows users to select picture files and then categorize them into folders. Now I'm having two issues that are probably simple to fix but I only have a year of experience with vb so I just don't know how to fix them. The first and biggest issue is that once the user has selected and categorized a file, I want the program to select the next file in the folder that the first file was moved from. This way the number of clicks required is minimized. However I have no clue what I would need to do in order to accomplish this.
Also, my other problem is that I want to be able to find the indexof a quotation mark but whenever I put it in the parameter it just reads it as a quote. If anyone could help with these problems that would be fantastic. |
|
|||
|
Not sure about #1 yet but you could do this for
#2 Code:
Dim strTest As String = "He said ""Help me please"""
Dim intIndex As Integer = strTest.IndexOf(ControlChars.Quote)
__________________
If someone has helped you please rate them.
|
|
|||
|
How are you keeping track of the files? Are you using a list, a table, etc.. ? Some code for #1 would help us out.
__________________
If someone has helped you please rate them.
|
|
|||
|
Well basically what happens is in the designer the user selects an image file they want to move using an open file dialog and the image is displayed in a picture box. Then they select a folder for it to be moved into using a folder browser dialog. The program then moves the file to the selected folder. The program works fine and they could just continue selecting a new file but I want to make it easier and have the program automatically open the next file in the folder that the original file they selected was located in. Here's the code to move the file.
System.IO.File.Move(txtLocation.Text, txtDirectory.Text & folderName & newName & ".jpg") Btw, thanks a ton for the help on #2 |
|
|||
|
I used an OpenFileDialog control to get the intial file(s) and a FolderBrowserDialog control to determine where to send the files. I used a CheckBox to determine whether I was processing a single file or multiple files. Right now it asks each time for where to put the files, it could be easily modified to store the initial folder path and then use that for each repetition. How it determines how many files it is to process could be easily modified base on your criteria, also.
Well here's a start on #2 for you: Code:
Private Sub btnGetImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetImage.Click
'get initial filelist
ofdOpenFile.InitialDirectory = "C:\"
ofdOpenFile.Filter = "Image Files (*.bmp,*.jpg,*.gif,*.png)|*.bmp;*.jpg;*.gif;*.png|All Files (*.*)|*.*"
ofdOpenFile.FilterIndex = 1
ofdOpenFile.Multiselect = False
If ofdOpenFile.ShowDialog() = Windows.Forms.DialogResult.OK Then
'get initial filelist
If chkProcessMultipleFiles.Checked Then
'process all the files in the folder
Dim ListOfFiles As New ArrayList
Dim di As New IO.DirectoryInfo(IO.Path.GetDirectoryName(ofdOpenFile.FileName))
ListOfFiles.AddRange(di.GetFiles("*.jpg"))
ListOfFiles.AddRange(di.GetFiles("*.bmp"))
ListOfFiles.AddRange(di.GetFiles("*.png"))
ListOfFiles.AddRange(di.GetFiles("*.gif"))
For FileCnt As Integer = 0 To ListOfFiles.Count - 1
If Not ProcessNextFile(ListOfFiles(FileCnt).ToString) Then
'stop processing files
Exit For
End If
Next
Else
'process the single selected file
ProcessNextFile(ofdOpenFile.FileName)
End If
End If
End Sub
Private Function ProcessNextFile(ByVal FilePathAndName As String) As Boolean
'find out where to move it to
fbdSaveToFolder.Description = "Select the folder to save the image " & Environment.NewLine & IO.Path.GetFileName(FilePathAndName)
fbdSaveToFolder.RootFolder = Environment.SpecialFolder.MyComputer
If fbdSaveToFolder.ShowDialog() = Windows.Forms.DialogResult.Cancel Then
Return False
End If
'move file to path selected
My.Computer.FileSystem.MoveFile(FilePathAndName, _
My.Computer.FileSystem.CombinePath(fbdSaveToFolder.SelectedPath, IO.Path.GetFileName(FilePathAndName)))
Return True
End Function
__________________
If someone has helped you please rate them.
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|