|
Don't listen to him. You do NOT want to kill Explorer.exe.
|
|
|
|
|
It's a situation that, if you have to ask, you shouldn't be told. Because the way to replace explorer can also make a system nearly unusable. Which means by the time you know how to deal with not having explorer, you'll also find out how to replace it.
Until then, start reading up on the windows resource kits. They'll let you enable security policies that can do what you're looking for in a safe manner.
The true man wants two things: danger and play. For that reason he wants woman, as the most dangerous plaything.
|
|
|
|
|
I would like to have the functionality to: on click, edit a subitem in a Listview.
I am building an MP3 file ID3 Tag editor and am loading a listview with all the tracks found in a folder. I would like the ability to select a particular entries subitem, then edit it. I know the first column can be edited, but have been unable to work out how to do this for subitems. I know I can get the text from the subitem, or even replace the text in a subitem, but I'd rather have it behave just like it does when the first item in the row is selected for editing. (This makes sense?)
The CodeProject site has something like this, and I think it places a textbox over the selected cell for editing purposes - however it is coded in C# and as a noob, I do not know how to convert this to VB code. D'oh!
Any advice would be gratefully accepted.
I am using Visual Studio 2008 if that helps.
All the best,
Ross
|
|
|
|
|
There are plenty of C# to VB translation programs out on the InterWeb. Have a Google and play with one or two.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi all,
I want to select a folder from FolderBrowserDialog and write into a textbox and append all the files within the folder shown in the textbox as one file in the same folder...
Code sofar:
Private Sub BtnFolder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnFolder.Click
Dim MyFolderBrowser As New System.Windows.Forms.FolderBrowserDialog
MyFolderBrowser.Description = "Select the Folder"
MyFolderBrowser.ShowNewFolderButton = False
Dim dlgResult As DialogResult = MyFolderBrowser.ShowDialog()
If dlgResult = Windows.Forms.DialogResult.OK Then
Textbox1.Text = MyFolderBrowser.SelectedPath
End If
End Sub
The above code opens a FolderBrowserDialog and allows to select a folder and the selected path is copied to the textbox.
Now, i want to know how to append all the files within the selected folder and write as one new textfile by clicking a button.
Thanks
Vijay
|
|
|
|
|
File.ReadAllText will read any file, you can concatenate strings.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
|
Three things.
1 The Button1_Click should be
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
AppendFiles()
End Sub
You need to tell it that Button1_Click_1 handles the Click event.
2 This is a hodge-podge of VB.Net and VBScript. You don't need all that FSO stuff. Have a look at reading and writing textfiles on MSDN or help system.
3 Be careful with the folder path. It needs to end with '\' before you join the filename, but that's not what is in the textbox.
Having said that the basic idea seems sound, it just won't work. It's relying on e.g. MainFile being a variant which does not exist in VB.NET. (Look at the two assignments: ones a string the other a file object.)
It won't even compile if you have Option Explicit and Option Strict set (as they ought to be).
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
|
The line AppendFiles(TextBox1.Text, "c:\DB\append\Append.txt") just passes the folder into the sub not the files in the folder.
You also need to loop through the files in the folder. Something like this:
Dim theDir As DirectoryInfo = new DirectoryInfo(iFile);
Dim datFiles As FileInfo() = theDir.GetFiles("*.txt");
Using sw As StreamWriter = New StreamWriter(oFile, True, System.Text.Encoding.Default)
For Each (fi As FileInfo In datFiles)
Using sa As StreamReader = New StreamReader(fi.FullName, System.Text.Encoding.Default)
'read and write text
End Using
Next
End Using
Syntax might not be quite right - copied and edited from C# code - but the general idea is ok.
This is what your friend's Do...Loop was trying to do.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Im getting 2 errors in this line
For Each ( fi As FileInfo In datFiles)
1)fi not declared
2)')' expected
I declared fi as string but still there is an error.
|
|
|
|
|
Should be For Each fi As FileInfo in datFiles i.e. no ( or ).
That's what happens when you copy and paste from C# which requires ( and )
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Thanks a lot I have written the code for Read and write and its working fine now.
I need to write the file creation date for the appended files.
Code I wrote:
GetCreationTime(iFile)
The creation time for each time is different, but its writing the same date for all the files...
Is there anyother method that could help to write the file creation date and time???
|
|
|
|
|
This would get creation time for file
For Each fi As FileInfo In datFiles
Dim created As DateTime = fi.CreationTime
Using sa As StreamReader = New StreamReader(fi.FullName, System.Text.Encoding.Default)
'read and write text
End Using
Next
I don't know where you're calling GetCreationTime() but it looks like you are passing in the folder and not the files.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Thanks a lot, that works fine.
Im using CreationTime() while writing the file.
|
|
|
|
|
|
vijay2482 wrote: If the header is found again in the next file
Does this mean that there may not be a header in a file? Or should it be When the header is found ?
In the first case (i.e. IF) then you have no guarantee that the first file read will contain a header so you need to do something like this.
Dim theDir As DirectoryInfo = new DirectoryInfo(iFile);
Dim datFiles As FileInfo() = theDir.GetFiles("*.txt");
Using sw As StreamWriter = New StreamWriter(oFile, True, System.Text.Encoding.Default)
'Write the header lines to output file
For Each fi As FileInfo In datFiles
Using sa As StreamReader = New StreamReader(fi.FullName, System.Text.Encoding.Default)
'read line from input
If 'header line' Then
'Skip it
Else
'write to output
End If
End Using
Next
End Using
You can write the header either by reading a special header.txt file that only contains header lines (and is not in the folder you're searching) or by hard coding the text as strings. The first way is better because if the headers change you don't need to change the code just the txt file.
If it's the second case (i.e. all files have header, you could do something like this.
Dim theDir As DirectoryInfo = new DirectoryInfo(iFile);
Dim datFiles As FileInfo() = theDir.GetFiles("*.txt");
Using sw As StreamWriter = New StreamWriter(oFile, True, System.Text.Encoding.Default)
Dim skipHeader as Boolean = False
For Each fi As FileInfo In datFiles
Using sa As StreamReader = New StreamReader(fi.FullName, System.Text.Encoding.Default)
'read input line
If 'header line' And Not skipHeader Then
'write output line - first line of header
'read input line - second line of header
'write output line
skipHeader = True
Else
'write output line
End If
End Using
Next
End Using
Note that this assumes there's only one or two header lines.
Note also that this is pseudocode mixed with VB not pure VB.
There's two problems with this
vijay2482 wrote: if name.contains("Nom du Modéle") or if name.contains("----") then
else
'read and write
End If
1 You don't need the second if.
2 When you find a header you still need to do a read, the best way is to do the read then the test for header as in the two bits I've done.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
|
Look at what WriteHeader() does and where it originally came from. You're not doing the same thing here.
In this code you have not done a read of the first file so there's nothing to write.
I think some of the problems come from you trying to hack one program (i.e. the one that did parent and child for a single file) into another one that concatenates files while stripping out header lines in all but the first file. The logic of the two programs is different and you need to think about it before coding.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Here's a better solution for when all files have headers.
Dim theDir As DirectoryInfo = new DirectoryInfo(iFile);
Dim datFiles As FileInfo() = theDir.GetFiles("*.txt");
Using sw As StreamWriter = New StreamWriter(oFile, True, System.Text.Encoding.Default)
'Read and write first file including headers
Dim fi As FileInfo = datFiles(0)
Using sa As StreamReader = New StreamReader(fi.FullName, System.Text.Encoding.Default)
'read input line
'write output line
End Using
' Read and write subsequent files excluding headers
For i As Integer = 1 To datFiles.Length()-1
fi = datFiles(i)
Using sa As StreamReader = New StreamReader(fi.FullName, System.Text.Encoding.Default)
'read input line
If 'header line' Then
' skip header line - do nothing
Else
'write output line
End If
End Using
Next i
End Using
Much neater and gets rid of awful skipHeaders flag.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
How is it possible to do a read befor declaring the streamreader???
Using sw As StreamWriter = New StreamWriter(oFile, True, System.Text.Encoding.Default)
'Read and write first file including headers
Dim fi As FileInfo = datFiles(0)
Using sa As StreamReader = New StreamReader(fi.FullName, System.Text.Encoding.Default)
'read input line
'write output line
End Using
|
|
|
|
|
'Read and write first file including headers
is a comment - if you read the code you'll see that it does declare sa at the appropriate place.
The comments in the using blocks do need to be replaced by code.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
|
Here's an annotated version of your code.
You need to think about the logic of the code rather than just hacking.
Roughly it is something like this NOTE this is not VB it's just looks a bit like VB:
Fill the pf array
Using streamreader for first file
read and write two header lines
Loop while data lines
read and write data line
End Loop
End Using 'Closes streamreader
For second and subsequent files in folder
Using streamreader for first file
Loop while input lines
read input line
If header line Then
'do nothing
else
'write data line
End If
End Loop
End Using 'Closes streamreader
Next
Unless you get the logic clear you'll keep stumbling around wondering why things don't work or give the output you expect.
'-------------------------------------------------------------
'Change the parameter name iFile to something more meaningful
'It's not the file name but the folder name
'--------------------------------------------------------------
Private Sub AppendFiles(ByVal iFile As String, ByVal oFile As String)
Dim temp As String
Dim name As String
Dim comp As String
Dim desF As String
Dim desAF As String
Dim desA As String
Dim desAA As String
Dim ecn As String
Dim dnf As String
Dim repDNF As String
Dim repASM As String
Dim pF(10) As Integer
Dim NbOfSpaces As Integer = 0
Dim theDir As DirectoryInfo = New DirectoryInfo(iFile)
Dim datFiles As FileInfo() = theDir.GetFiles("*.txt")
Using sw As StreamWriter = New StreamWriter(oFile, True, System.Text.Encoding.Default)
'--------------------------------------------------------------------------------------------
' Call FillPF sub here, or move the code marked XXXX to here (I've done that). You don't need any files to do what it does
'--------------------------------------------------------------------------------------------
'---------------------------------------------------------------------------------------------
'XXXX Why is this being done 0 to 10 times? All it does is assign entries to the pf Array
'that's why I did it as a sub called FillPF() and got rid of the loop and it can be done above
For i = 0 To 10
pF(0) = temp.IndexOf("Nom du Modèle")
pF(1) = temp.IndexOf("AEC_COMPATIBILITY")
pF(2) = temp.IndexOf("AEC_STANDARD_DESCRIPTION_FRENCH")
pF(3) = temp.IndexOf("AEC_FREE_DESCRIPTION_FRENCH")
pF(4) = temp.IndexOf("AWW_STANDARD_DESCRIPTION")
pF(5) = temp.IndexOf("AEC_FREE_DESCRIPTION_ENGLISH")
pF(6) = temp.IndexOf("AEC_ECN")
pF(7) = temp.IndexOf("DNF")
pF(8) = temp.IndexOf("REP_DNF")
pF(9) = temp.IndexOf("REP_ASM")
Next
'---------------------------------------------------------------------------------------------
'Read and write first file including headers
'*** iFile is the path, we've been through this before; StreamReader reads a file it can't read a folder
'*** Change the name to something like inputPath and it will be less misleading.
Using sa As StreamReader = New StreamReader(iFile, System.Text.Encoding.Default)
'-----------------------------------------------------------------------
'This block reads and writes the two header lines in the first file
'-----------------------------------------------------------------------
temp = sa.ReadLine()
name = temp.Substring(0, pF(1))
comp = temp.Substring(pF(1), pF(2) - pF(1))
desF = temp.Substring(pF(2), pF(3) - pF(2))
desAF = temp.Substring(pF(3), pF(4) - pF(3))
desA = temp.Substring(pF(4), pF(5) - pF(4))
desAA = temp.Substring(pF(5), pF(6) - pF(5))
ecn = temp.Substring(pF(6), pF(7) - pF(6))
dnf = temp.Substring(pF(7), pF(8) - pF(7))
repDNF = temp.Substring(pF(8), pF(9) - pF(8))
repASM = temp.Substring(pF(9), temp.Length - pF(9))
sw.WriteLine(name & comp & desF & desAF & desA & desAA & ecn & dnf & repDNF & repASM & "CREATED_DATE")
sw.WriteLine(sa.ReadLine())
'-----------------------------------------------------------------------
End Using
'------------------------------------------------------------------------------------------
' This opens the first file for reading, you can't write the headers until you've done this
' and you have to take into account the two lines you attempt to read above
'i.e. you must read and write them before the loop reads the data lines
'So you need to move these two lines to before the block that reads the header lines.
'Also get rid of the Using and End Using above.
'------------------------------------------------------------------------------------------
Dim fi1 As FileInfo = datFiles(0)
Using sa As StreamReader = New StreamReader(fi1.FullName, System.Text.Encoding.Default)
'------------------------------------------------------------------------------------------
While sa.Peek() >= 0
temp = sa.ReadLine()
name = temp.Substring(0, pF(1))
comp = temp.Substring(pF(1), pF(2) - pF(1))
desF = temp.Substring(pF(2), pF(3) - pF(2))
desAF = temp.Substring(pF(3), pF(4) - pF(3))
desA = temp.Substring(pF(4), pF(5) - pF(4))
desAA = temp.Substring(pF(5), pF(6) - pF(5))
ecn = temp.Substring(pF(6), pF(7) - pF(6))
dnf = temp.Substring(pF(7), pF(8) - pF(7))
repDNF = temp.Substring(pF(8), pF(9) - pF(8))
repASM = temp.Substring(pF(9), temp.Length - pF(9))
sw.WriteLine(name & comp & desF & desAF & desA & desAA & ecn & dnf & repDNF & repASM & Created)
End While
End Using
' Read and write subsequent files excluding headers
For i As Integer = 1 To datFiles.Length() - 1
fi1 = datFiles(i)
Using sa As StreamReader = New StreamReader(fi1.FullName, System.Text.Encoding.Default)
'read input line
While sa.Peek() >= 0
temp = sa.ReadLine()
name = temp.Substring(0, pF(1))
comp = temp.Substring(pF(1), pF(2) - pF(1))
desF = temp.Substring(pF(2), pF(3) - pF(2))
desAF = temp.Substring(pF(3), pF(4) - pF(3))
desA = temp.Substring(pF(4), pF(5) - pF(4))
desAA = temp.Substring(pF(5), pF(6) - pF(5))
ecn = temp.Substring(pF(6), pF(7) - pF(6))
dnf = temp.Substring(pF(7), pF(8) - pF(7))
repDNF = temp.Substring(pF(8), pF(9) - pF(8))
repASM = temp.Substring(pF(9), temp.Length - pF(9))
'-------------------------------------------------------------------------
' Is this test right? It means the second line in the file will be written
' out. But will only be ------------------------------------ line.
'-------------------------------------------------------------------------
If name.Contains("Nom du Modélé") Then
' skip header line - do nothing
Else
'write output line
sw.WriteLine(name & comp & desF & desAF & desA & desAA & ecn & dnf & repDNF & repASM & created)
End If
End While
End Using
Next i
End Using
'------------------------------------------------------------
'Where did the End Sub go to? Is there more code after this?
'------------------------------------------------------------
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Thanks for the explanations of the code.
Will try and let u know...
Thanks once again...
|
|
|
|
|