Results 1 to 32 of 32

Thread: [Help] My app isn't working right

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    15

    [Help] My app isn't working right

    I have an app that if you have the button checked and press a button the following should happen:

    1) The app loops through the folder and searches for files that have the matching extension on them (FileType1)
    2) It then renames the file without the extension to .ORIGINAL (If checked)
    3) The .MODIFIED version of the file then has the .MODIFIED removed, making it the same name as the old file

    My code seems right but it doesn't change the files. I have no errors or anything. Please help

    My code:
    Code:
    Public Class Form1
        Dim FileType1 As String
        Dim FileType2 As String
        Dim Match As Double
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If CheckBox4.Checked = True Then
                Strings1()
                LoopThruDirectory()
            Else
                Strings2()
                LoopThruDirectory()
            End If
        End Sub
    
        Sub Strings1()
            FileType1 = "MODIFIED"
            FileType2 = "ORIGINAL"
        End Sub
    
        Sub Strings2()
            FileType1 = "ORIGINAL"
            FileType2 = "MODIFIED"
        End Sub
    
        Sub LoopThruDirectory()
    
            Dim strPath As String
            Dim strFile As String
            Dim x As Integer
    
            strPath = "C:\Nexon\Combat Arms\Game\22\"
            strFile = Dir(strPath)
    
            Do While strFile <> ""
                x = x + 1
                If Dir(strPath + strFile + "." + FileType1) <> "" Then
                    If CheckBox4.Checked = False Then
                        My.Computer.FileSystem.RenameFile(strPath + strFile, strFile + "." + FileType2)
                        My.Computer.FileSystem.RenameFile(strPath + strFile + "." + FileType1, strFile)
                    ElseIf CheckBox4.Checked = True Then
                        My.Computer.FileSystem.RenameFile(strPath + strFile, strFile + "." + FileType2)
                        My.Computer.FileSystem.RenameFile(strPath + strFile + "." + FileType1, strFile)
                    End If
                End If
                strFile = Dir()    ' Get next entry.
            Loop
    
        End Sub
    
        Private Sub CheckBox4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox4.CheckedChanged
            If CheckBox4.Checked = True Then
                CheckBox4.ForeColor = Color.Green
            Else
                CheckBox4.ForeColor = Color.Red
            End If
        End Sub
    End Class

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: [Help] My app isn't working right

    RenameFile requires full paths for both parameters, i.e. "c:\test folder\textfile.txt"

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    15

    Re: [Help] My app isn't working right

    It does name it all

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: [Help] My app isn't working right

    don't use Dir() .... use the IO.Directory to path to the correct location, then use the .GetFiles method to return a list of your files (should come back to you as an array of strings) ... loop through THAT

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: [Help] My app isn't working right

    My.Computer.FileSystem.RenameFile(strPath + strFile, strFile + "." + FileType2)

    what is the exact value of strPath + strFile?

    the 2nd parameter has no path - strFile + "." + FileType2

    also if for example strFile = "test.txt" then strFile + "." + FileType2 would be "test.txt.MODIFIED"

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    15

    Re: [Help] My app isn't working right

    Quote Originally Posted by techgnome View Post
    don't use Dir() .... use the IO.Directory to path to the correct location, then use the .GetFiles method to return a list of your files (should come back to you as an array of strings) ... loop through THAT

    -tg
    How do you do that? Sorry, im rather a noob


    They're defined here:

    Code:
            strPath = "C:\Nexon\Combat Arms\Game\22\"
            strFile = Dir(strPath)
    And ya i know what it would equal, i wrote this myself -.-
    It just isn't renaming them

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: [Help] My app isn't working right

    vb Code:
    1. Dim files() As String = IO.Directory.GetFiles("C:\Nexon\Combat Arms\Game\22", "*.*")

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: [Help] My app isn't working right

    Quote Originally Posted by Owner Fritz View Post
    It just isn't renaming them
    because as i told you, you're not passing a full path in the 2nd parameter of renamefile

  9. #9

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    15

    Re: [Help] My app isn't working right

    Quote Originally Posted by .paul. View Post
    vb Code:
    1. Dim files() As String = IO.Directory.GetFiles("C:\Nexon\Combat Arms\Game\22", "*.*")
    So how do i loop through and use that?


    @paul
    So how do i fix that?

  10. #10
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: [Help] My app isn't working right

    Quote Originally Posted by Owner Fritz View Post
    So how do i loop through and use that?
    vb Code:
    1. Dim files() As String = IO.Directory.GetFiles("C:\Nexon\Combat Arms\Game\22", "*.*")
    2. for each file as string in files
    3.     'your code
    4. next

    Quote Originally Posted by Owner Fritz View Post
    @paul
    So how do i fix that?
    Quote Originally Posted by Owner Fritz View Post
    1) The app loops through the folder and searches for files that have the matching extension on them (FileType1)
    2) It then renames the file without the extension to .ORIGINAL (If checked)
    3) The .MODIFIED version of the file then has the .MODIFIED removed, making it the same name as the old file
    i can't help you without a clear explanation of what you want your program to do

  11. #11

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    15

    Re: [Help] My app isn't working right

    Quote Originally Posted by .paul. View Post
    vb Code:
    1. Dim files() As String = IO.Directory.GetFiles("C:\Nexon\Combat Arms\Game\22", "*.*")
    2. for each file as string in files
    3.     'your code
    4. next





    i can't help you without a clear explanation of what you want your program to do
    I have modified .rez files and normal .rez files in a folder.

    The modified ones are named blabla.rez.MODIFIED and the originals are named blabla.rez

    I want the program to when you hit the start button, if you have the checkbox that says mods checked, the program renames the blabla.rez to blabla.rez.ORIGINAL and the blabla.rez.MODIFIED to blabla.rez. If you don't have it checked, it does the opposite.

    Does that make sense?

  12. #12
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: [Help] My app isn't working right

    Quote Originally Posted by Owner Fritz View Post
    the program renames the blabla.rez to blabla.rez.ORIGINAL and the blabla.rez.MODIFIED to blabla.rez. If you don't have it checked, it does the opposite.
    am i correct in saying, if the checkbox isn't checked, it renames the blabla.rez to blabla.rez.MODIFIED and the blabla.rez.ORIGINAL to blabla.rez?

  13. #13
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: [Help] My app isn't working right

    try this:

    vb Code:
    1. Sub LoopThruDirectory()
    2.  
    3.     Dim strPath As String
    4.    
    5.     strPath = "C:\Nexon\Combat Arms\Game\22\"
    6.  
    7.     Dim files = (From file As String In IO.Directory.GetFiles(strPath, "*.*") _
    8.                 Select New With { _
    9.                 .oldName = file, _
    10.                 .newName = If(file.EndsWith(FileType1), file.Replace("." & FileType1, ""), _
    11.                               If(file.EndsWith(FileType2), file.Replace("." & FileType2, ""), _
    12.                                   file & "." & FileType1))}).ToList
    13.  
    14.     For Each f In files
    15.         'test this before you run it
    16.         msgbox("old name = " & f.oldname & environment.newline & "new name = " & f.newname)
    17.         'IO.File.Move(f.oldName, f.newName)
    18.     Next
    19.  
    20. End Sub
    Last edited by .paul.; Mar 27th, 2010 at 10:37 PM.

  14. #14

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    15

    Re: [Help] My app isn't working right

    Quote Originally Posted by .paul. View Post
    am i correct in saying, if the checkbox isn't checked, it renames the blabla.rez to blabla.rez.MODIFIED and the blabla.rez.ORIGINAL to blabla.rez?
    Yes but it checks if there IS a file with other extension (.ORIGINAL or .MODIFIED) before it renames them. If there isn't one, it leaves that file alone.

  15. #15
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: [Help] My app isn't working right

    i'm still not sure exactly what you mean. how would the files in the screenshot be renamed?
    Attached Images Attached Images  

  16. #16

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    15

    Re: [Help] My app isn't working right

    Ok, the text1.txt is the original file and the MODIFIED is the modified version.

    The ORIGINAL files aren't needed to start.

    If the check box is not checked and you hit START, it checks to see if there is a ORIGINAL file. If there isn't, it just runs without renaming anything. If it is checked, it looks to see if there is a .MODIFIED version of the file file. If there is one, it renames the text1.txt to text1.txt.ORIGINAL and then then text1.txt.MODIFIED to text1.txt.

  17. #17
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: [Help] My app isn't working right

    can you demonstrate by typing them out?

    i.e.

    test1.txt renamed ???
    test1.txt.ORIGINAL renamed ???
    test2.txt.ORIGINAL renamed ???
    test3.txt renamed ???
    test3.txt.MODIFIED renamed ???
    test4.txt renamed ???
    test5.txt.MODIFIED renamed ???

  18. #18

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    15

    Re: [Help] My app isn't working right

    Starts as:

    text1.txt
    text1.txt.MODIFIED
    text2.txt

    Ok so first we aren't going to have it checked.
    [ ] Box
    I hit the start button but it doesn't change anything because it doesn't find any .ORIGINAL files

    [X] Box
    I hit the start button and it looks for .MODIFIED files. If it finds one, it looks for the same file without a .MODIFIED on it. So for instance, it might see text1.txt.MODIFIED then it would look for a text1.txt. If it finds it, it changes the text1.txt to text1.txt.ORIGINAL:

    text1.txt.ORIGINAL
    text1.txt.MODIFIED
    text2.txt

    The text2.txt is not changed because it didn't find a text2.txt.MODIFIED.
    Next, it removes .MODIFIED from the other file.

    text1.txt.ORIGINAL
    text1.txt
    text2.txt

    See how i mean? Just the opposite if it's not checked

  19. #19
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: [Help] My app isn't working right

    ok this should work. run it first with the msgbox + the moves commented out to test it, then if it's ok uncomment the 2 io.file.move lines:

    vb Code:
    1. Sub LoopThruDirectory()
    2.  
    3.     Dim strPath As String
    4.  
    5.     strPath = "C:\Nexon\Combat Arms\Game\22\"
    6.  
    7.     Dim files = (From file As String In IO.Directory.GetFiles(strPath, "*." & FileType1) _
    8.                     Select New With { _
    9.                     .oldName = If(IO.File.Exists(file.Replace("." & FileType1, "")), file.Replace("." & FileType1, ""), Nothing), _
    10.                     .newName = .oldName & "." & FileType2, _
    11.                     .oldName2 = file, _
    12.                     .newName2 = file.Replace("." & FileType1, "")}).ToList
    13.  
    14.    
    15.     For Each f In files
    16.         If f.oldName <> Nothing Then
    17.             'test this before you run it
    18.             MsgBox("old name = " & f.oldName & Environment.NewLine & "new name = " & f.newName & Environment.NewLine & "old name2 = " & f.oldName2 & Environment.NewLine & "new name2 = " & f.newName2)
    19.             'IO.File.Move(f.oldName, f.newName)
    20.             'IO.File.Move(f.oldName2, f.newName2)
    21.         End If
    22.     Next
    23.  
    24. End Sub

  20. #20

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    15

    Re: [Help] My app isn't working right

    So does that check if there is a .MODIFIED or .ORIGINAL version before renaming?

  21. #21
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: [Help] My app isn't working right

    it only selects files of FileType1, whichever that might be:

    Code:
    From file As String In IO.Directory.GetFiles(strPath, "*." & FileType1)

  22. #22

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    15

    Re: [Help] My app isn't working right

    Ok thanks I'll try it

    I get errors :S

  23. #23
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: [Help] My app isn't working right

    this:

    Code:
    Dim files = (From file As String In IO.Directory.GetFiles(strPath, "*." & FileType1) _
                        Select New With { _
                        .oldName = If(IO.File.Exists(file.Replace("." & FileType1, "")), file.Replace("." & FileType1, ""), Nothing), _
                        .newName = .oldName & "." & FileType2, _
                        .oldName2 = file, _
                        .newName2 = file.Replace("." & FileType1, "")}).ToList
    should be exactly as it is here. no empty lines between the code

  24. #24

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    15

    Re: [Help] My app isn't working right

    Oh ill try that

  25. #25
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: [Help] My app isn't working right

    did that work how you expected?

  26. #26

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    15

    Re: [Help] My app isn't working right

    Nothing happened. This is my folder:

  27. #27
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: [Help] My app isn't working right

    look back at my screenshot in post #15 + see the difference

    try this modified version:

    vb Code:
    1. Sub LoopThruDirectory()
    2.  
    3.     Dim strPath As String
    4.  
    5.     strPath = "C:\Nexon\Combat Arms\Game\22\"
    6.  
    7.     Dim files = (From file As String In IO.Directory.GetFiles(strPath, "*." & FileType1) _
    8.                     Select New With { _
    9.                     .oldName = If(IO.File.Exists(file.Replace(FileType1, "rez")), file.Replace(FileType1, "rez"), Nothing), _
    10.                     .newName = file.Replace(FileType1, FileType2) , _
    11.                     .oldName2 = file, _
    12.                     .newName2 = file.Replace(FileType1, "rez")}).ToList
    13.  
    14.    
    15.     For Each f In files
    16.         If f.oldName <> Nothing Then
    17.             'test this before you run it
    18.             MsgBox("old name = " & f.oldName & Environment.NewLine & "new name = " & f.newName & Environment.NewLine & "old name2 = " & f.oldName2 & Environment.NewLine & "new name2 = " & f.newName2)
    19.             'IO.File.Move(f.oldName, f.newName)
    20.             'IO.File.Move(f.oldName2, f.newName2)
    21.         End If
    22.     Next
    23.  
    24. End Sub

  28. #28

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    15

    Re: [Help] My app isn't working right

    Thanks, that worked. Now I just want to know how i can only change the file if the name contains _T_, or _M_, or UID_ if a checkbox is checked. Otherwise thats perfect

  29. #29
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: [Help] My app isn't working right

    ok show us your code you have so far, in particular the new checkbox + give an example of some file names you'd want to change if checked + if not checked

  30. #30
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: [Help] My app isn't working right

    ok. here's a wild untested shot at it then:

    vb Code:
    1. Dim files = (From file As String In IO.Directory.GetFiles(strPath, "*." & FileType1) _
    2.                      Where If(checkbox1.checked, file.Contains("_T_") OrElse file.Contains("_M_") OrElse file.Contains("UID_"), file = file) _
    3.                         Select New With { _
    4.                         .oldName = If(IO.File.Exists(file.Replace(FileType1, "rez")), file.Replace(FileType1, "rez"), Nothing), _
    5.                         .newName = file.Replace(FileType1, FileType2), _
    6.                         .oldName2 = file, _
    7.                         .newName2 = file.Replace(FileType1, "rez")}).ToList

  31. #31

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    15

    Re: [Help] My app isn't working right

    I deleted my old code cause it sucked and didn't work :O
    What I want is it so if
    [ ] = 1 (_T_)
    [ ] = 2 (_M_)
    [ ] = 3 (UID_)
    [ ] = 4 (Anything else)

    If checkbox 1 is checked, it changes files with _T_, two _M_, three UID_, and last everything else that doesn't have those. That make sense?

  32. #32

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    15

    Re: [Help] My app isn't working right

    Now it stopped working entirely -.-

Posting Permissions

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



Click Here to Expand Forum to Full Width