+ Reply to Thread
Results 1 to 5 of 5

Thread: Trouble Opening Files

  1. #1
    bigklaxer is offline VB.NET Forum Newbie bigklaxer is on a distinguished programming path ahead
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Jul 2009
    Age
    19
    Posts
    6
    Reputation
    0

    Question Trouble Opening Files

    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.

  2. #2
    demausdauth is offline VB.NET Forum Master demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame
    .NET Framework
    .NET 2.0
    Join Date
    Mar 2008
    Location
    Minnesota
    Posts
    275
    Reputation
    221

    Default

    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.

  3. #3
    demausdauth is offline VB.NET Forum Master demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame
    .NET Framework
    .NET 2.0
    Join Date
    Mar 2008
    Location
    Minnesota
    Posts
    275
    Reputation
    221

    Default

    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.

  4. #4
    bigklaxer is offline VB.NET Forum Newbie bigklaxer is on a distinguished programming path ahead
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Jul 2009
    Age
    19
    Posts
    6
    Reputation
    0

    Default

    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

  5. #5
    demausdauth is offline VB.NET Forum Master demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame
    .NET Framework
    .NET 2.0
    Join Date
    Mar 2008
    Location
    Minnesota
    Posts
    275
    Reputation
    221

    Default

    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.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts