|
|
How can I search all the files available on my computer (C,D,E,F...) drives like search functionality in windows.
The application should search the subfolder as well in the drives.
I want to have a list of all the files available in my computer.
Thanks In Advance
|
|
|
|
|
That's going to be slooow..
The recipe first;- List all drives (Google for a snippet)
- Create a recursive function to loop all folders in that drive
- Proces all files and folders that the function returns
ejaz_pk wrote: like search functionality in windows.
That one allows you to search "within" files, and is more complex then the recipe above. Do you want to "list" all your files, or do you want to search their contents?
I are Troll
|
|
|
|
|
I just want file names list and path of the files.
|
|
|
|
|
The hardest part would be the recursive funtion to scan the folders. There's an example on that over here[^], and also on the Knowledge Base[^].
The rest is up to you
I are Troll
|
|
|
|
|
Easily done by shelling to a DOS command that creates a text file, then parsing this if necessary:
The following DOS command will create a file called Output.txt with a list of all files (not including system or hidden) on drive c: - the /s recurses subdirectories, and the /b restricts the output to filename only.
DIR C: /s /b >Output.txt
====================================
Transvestites - Roberts in Disguise!
====================================
|
|
|
|
|
How to Redirect a LinkLabel from one window form to another window form in VB 2005?
|
|
|
|
|
form.show
or
form.ShowDialog
SOFTDEV
If you have knowledge, let others light their candles at it. [ Let's work to help developers, not make them feel stupid ]
|
|
|
|
|
Hi,everyone.I am hoping that the text that I input in the textbox can be captured in the
excel each sheet ,column 3, rows 2-20 for example.
Code like under,I think there are many errors in it,please tell me how to write it,please.
Thanks!
Imports Office = Microsoft.Office.Core
Imports Microsoft.Office.Interop.Excel
Private Sub OperateExcel()
Dim Xls As Object
Dim Xlsbook As Excel.Workbook
Dim Xlssheet As Excel.Worksheet
Dim Xlsrange As Excel.Range
Xls = CreateObject("excel.application")
Xlsbook = Xls.Workbooks.open("D:\text.xls")
Xls.Visible = True
Xlssheet = Xlsbook.Worksheets("sheet1")
For Each Xlssheet In Xls.Xlsbook
Xlsrange = Xlssheet.Range("H3")
Xlsrange.Value = txtProduct.Text
Xlsrange = Xlssheet.Range("H4")
Xlsrange.Value = txtName.Text
Xlsrange = Xlssheet.Range("H5")
Xlsrange.Value = txtNum.Text
Next
Xlsbook.Close()
Xls.Quit()
releaseObject(Xls)
releaseObject(Xlsbook)
releaseObject(Xlssheet)
End Sub
modified on Friday, May 7, 2010 1:12 AM
|
|
|
|
|
Where to start...
I am not exactly sure what you are trying to achieve, and I take it you assembled this code from examples, or copied it as is.
So let's start from the beginning. If you suspect that this code has errors, the first thing you should do is put all the code inside the sub into a try catch clause:
Private Sub OperateExcel()
Try
'the rest of the code here'
Catch ex as Exception
MsgBox(ex.tostring)
End Try
End Sub
Then at least you'll find out if this code works at all. After that comes the important part, comparing what this code does to what you want it to do.
A simple way to start is to write comments into the code. One comment for each step, and then fill in the code bits doing each step.
My advice is free, and you may get what you paid for.
|
|
|
|
|
Hi,Johan,thanks for your suggestion.I apologize for the late reply...I used try catch clause in my code and then it told me an exception like this:
system.runtime.interop services.COMException(0x80020003):member not found.
it comes from:xlssheet = xlsworkbook.worksheet(1)
Could you give me suggestions to solve it?Thank you
modified on Saturday, May 8, 2010 9:35 PM
|
|
|
|
|
Hi sanyexian,
I changed your code a little bit so that it works. Still you might encounter many traps, since communication with Excel (i.e. COM / Office) can be very tricky sometimes. Also don't forget the small things, like making your assembly COM visible (project properties). You'll find tons of material about the issue here and in the web - and a lot is worth reading. Good luck
Sub OperateExcel()
' Compile with Option Strict Off to allow late binding.
Dim xlsApp As Object
Dim xlsBook As Object
Dim xlsSheet As Object
xlsApp = CreateObject("Excel.Application")
' Late bind an instance of an Excel workbook.
xlsBook = xlsApp.Workbooks.Add
' Late bind an instance of an Excel worksheet.
xlsSheet = xlsBook.Worksheets(1)
xlsSheet.Activate()
' Show the application.
xlsSheet.Application.Visible = True
For Each xlsSheet In xlsBook.worksheets
' put your text into the cells in a simpler way
xlsSheet.Range("H3").Value = "txtProduct"
xlsSheet.Range("H4").Value = "txtName"
xlsSheet.Range("H5").Value = "txtNum"
' A more useful way since you can iterate through rows/colums
' Here: Place some text in the second row of the sheet.
xlsSheet.Cells(2, 8) = "This is column H row 2"
Next
xlsBook.SaveAs("D:\text.xls")
xlsBook.Close()
xlsApp.Quit()
xlsSheet = Nothing
xlsBook = Nothing
xlsApp = Nothing
End Sub
|
|
|
|
|
How did that saying go again, about giving a man a fish...?
My advice is free, and you may get what you paid for.
|
|
|
|
|
You're surely right on one side. On the other side I've experienced so many other traps communicating with Office (and still do, as you know from my own thread ), that he will have to dig deeper for himself anyway. Probaly he even gets more motivated by having an easier start
|
|
|
|
|
Hi,Michael.I apologize for the late reply.Thanks for your suggestion.Now I could open a Excel file,but there is an error stoped me going on.
xlsSheet = xlsBook.Worksheets(1)
I watched "xlsSheet",it display that its value was "nothing" and VS told me " HRESULT:0x80020003 (DISP_E_MEMBERNOTFOUND))"
I don't know why it happened...the file had been opened ,but why it could not get its worksheet?
Plzzz help me ,thank you!
modified on Saturday, May 8, 2010 9:34 PM
|
|
|
|
|
Hi Sanyexian,
you can try xlsSheet = xlsBook.Worksheets.Add to add a new worksheet instead of referring the first available sheet with "1" (as suggested: play with IntelliSense!). The code is very basic anyway, you will need to catch exceptions (Try... Catch) and much more. You might also want to download some samples from the web and learn from them - as I wrote COM-Interaction can be tricky.
Good luck!
|
|
|
|
|
I have a little tool that I use in my job for running scripts on remote machines and gathering information. Currently I'm doing this through the process class and plink/SSH which works ok. My company is looking at doing away with the SSH server on the boxes which leaves me looking for another method. I know there is psexec which might work although by default most ports are blocked by the firewall, so not positive. Is there any way I can do it programatically without the need to involve an additional application? Any method I use I need to be able to capture the output as the majority of scripts are for gathering information without logging into the server. Any help would be appreciated.
|
|
|
|
|
A simple alternative that I use for this kind of thing, is ftp. Obviously this requires an ftp server that you can upload things to from anywhere.
Its pretty straightforward, but I don't think it works with sftp.
Private Sub FTP_PutFile(ByVal DestinationFileName As String, ByVal SourceFileName As String, ByVal usr As String, ByVal pwd As String)
Dim brwsr As New System.Net.WebClient
Dim creds As New System.Net.NetworkCredential(usr, pwd)
Try
With brwsr
.Credentials = creds
Console.WriteLine("Uploading file...")
.UploadFile(DestinationFileName, SourceFileName)
Console.WriteLine("Upload successful.")
.Dispose()
End With
Catch ex As Exception
EC(ex)
End Try
End Sub
Example use:
FTP_PutFile("ftp://server.address.or.ip/file.extension", "c:\temp\file.extension", "user", "password")
Just replace the .UploadFile bit with .DownloadFile(SourceFileName, DestinationFileName) when you want to download the file from the server.
My advice is free, and you may get what you paid for.
|
|
|
|
|
I don't have any problems with getting files there as I have a network share that is accessible from all machines. I need a way to actually run the file or process on the remote machine though and capture the output of that file/process.
|
|
|
|
|
Sorry about that, I misunderstood the question. I am afraid I can't help you with this.
My advice is free, and you may get what you paid for.
|
|
|
|
|
I know the name of Domain on NT platform "MY_Domain_name".
I know the username "OU458778".
Is possibile to know the complete name of username????
With vb6, please.
|
|
|
|
|
What do you mean by complete name? Like My_Domain_name\OU458778 or just the user's name like John Smith?
|
|
|
|
|
yes! just the user's name like John Smith
|
|
|
|
|
I don't have a copy of VB6 to test this with, but this VBScript code should translate pretty closely. You just need to do a WMI query against the Win32_UserAccount class. Name is the User ID and FullName should be the formatted name.
strUserID = InputBox("Please enter the User ID you wish to find")
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objAccountColl = objWMIService.ExecQuery("Select * from Win32_UserAccount where Name = '" & strUserID & "'")
For Each objAccount in ObjAccountColl
strValue = "AccountType: " & objAccount.AccountType & vbCrLf & _
"Caption: " & objAccount.Caption & vbCrLf & _
"Description: " & objAccount.Description & vbCrLf & _
"Disabled: " & objAccount.Disabled & vbCrLf & _
"Domain: " & objAccount.Domain & vbCrLf & _
"FullName: " & objAccount.FullName & vbCrLf & _
"InstallDate: " & objAccount.InstallDate & vbCrLf & _
"LocalAccount: " & objAccount.LocalAccount & vbCrLf & _
"Lockout: " & objAccount.Lockout & vbCrLf & _
"Name: " & objAccount.Name & vbCrLf & _
"PasswordChangeable: " & objAccount.PasswordChangeable & vbCrLf & _
"PasswordExpires: " & objAccount.PasswordExpires & vbCrLf & _
"PasswordRequired: " & objAccount.PasswordRequired & vbCrLf & _
"SID: " & objAccount.SID & vbCrLf & _
"SIDType: " & objAccount.SIDType & vbCrLf & _
"Status: " & objAccount.Status
MsgBox strValue
Exit For
Next
|
|
|
|
|
ok tks for reply...
But i dont see where i insert the name of domain?
|
|
|
|