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
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
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
Dim files() As String = IO.Directory.GetFiles("C:\Nexon\Combat Arms\Game\22", "*.*")
for each file as string in files
'your code
next
Originally Posted by Owner Fritz
@paul
So how do i fix that?
Originally Posted by Owner Fritz
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
Dim files() As String = IO.Directory.GetFiles("C:\Nexon\Combat Arms\Game\22", "*.*")
for each file as string in files
'your code
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.
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?
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.
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.
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
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
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