|
Hey all, not 100% sure if this is the right forum for Visual Basic Scripting but i can only assume it is.
Basicly put my current script will let you type a directory into an input box
e.g C:\Temp\Files
then it will rename every file in there with the extension .txt to .bak
while all that works great,
i have subfolders and it will not change the extensions of the txt files in them
here is my current code for you to look at
FILEPATH=inputbox("What is the directory?")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set FileDirectory = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='" & FILEPATH & "'} Where " _
& "ResultClass = CIM_DataFile")
For Each objFile In FileDirectory
If objFile.Extension = "txt" Then
strbak = objFile.Drive & objFile.Path & objFile.FileName & "." & "bak"
objFile.Copy(strbak)
End If
Next
msgbox "Complete."
im pretty sure i have to use Win32_SubDirectory.Name but i have tried to implement it and failed
so can someone please help me to get my script to change subfolder file extensions?
|
|
|
|
|
I don't believe there is a built in mechanism for simulating following the file system hierarchy, so you'll have to create your own. You need to put the logic of renaming all the .txt files to .bak in a folder into a sub and then use recursion to walk the directory structure. So, you'll have a sub that accepts either a folder object or a string that is the path (your choice) and then within the sub you'll process all the files and then have it call itself for each folder within the supplied path. Here's some pseudocode:
sub ProcessFolder(folder)
foreach(file in folder.files)
rename file...
foreach(folder in folder.folders)
ProcessFolder(folder)
end sub
From your main script you'll just call the sub with for the root level of folder and then let it handle everything from there.
Keep It Simple Stupid! (KISS)
|
|
|
|
|
i got it working after finding some code that monitors a folder including subfolders
i just changed it around so that it checked for the extention and renamed it
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
strFolderName=inputbox("ENTER THE FULL BACKUP PATH")
msgbox "A messagebox will display on completion, this may take some time"
Set colSubfolders = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")
arrFolderPath = Split(strFolderName, "\")
strNewPath = ""
For i = 1 to Ubound(arrFolderPath)
strNewPath = strNewPath & "\\" & arrFolderPath(i)
Next
strPath = strNewPath & "\\"
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_DataFile where Path = '" & strPath & "'")
For Each objFile in colFiles
If objFile.Extension = "txt" Then
strBACKUP = objFile.Drive & objFile.Path & objFile.FileName & "." & "bak"
objFile.Copy(strBACKUP)
End If
Next
For Each objFolder in colSubfolders
GetSubFolders strFolderName
Next
Sub GetSubFolders(strFolderName)
Set colSubfolders2 = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")
For Each objFolder2 in colSubfolders2
strFolderName = objFolder2.Name
arrFolderPath = Split(strFolderName, "\")
strNewPath = ""
For i = 1 to Ubound(arrFolderPath)
strNewPath = strNewPath & "\\" & arrFolderPath(i)
Next
strPath = strNewPath & "\\"
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_DataFile where Path = '" & strPath & "'")
For Each objFile in colFiles
If objFile.Extension = "txt" Then
strBACKUP = objFile.Drive & objFile.Path & objFile.FileName & "." & "bak"
objFile.Copy(strBACKUP)
End If
Next
GetSubFolders strFolderName
Next
End Sub
thanks for the help!
|
|
|
|
|
How to copy data in a data table to another table in run time (by using VB.NET 2005)
|
|
|
|
|
This is disconnected from a DB ? You'd have to build the table to have the right format and copy the rows across.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
|
Dim NewTable as datatable = oldtable.copy
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi
How can I open a website from a windows application in any browser
Thanks
Sebastian
|
|
|
|
|
By using Process.Start with a URL, you can launch the default browser. To specify the browser, you'd need to find the exe on the HDD and know how to launch it with a URL.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Actually...This will launch any default browser at the URL you specify
Private Sub LaunchURL(byval URL as String)
Try
Process.Start(URL)
Catch ex as exception
End Try
End Sub
You can then use: LaunchURL("http://urlhere") from anywhere within your code..
The Try is needed because some browsers like Firefox will sometimes return an error for no reason...
Steven
|
|
|
|
|
in one of my application i am using mscomm32.ocx for fetching data from electronic weighbridge but in this case one problem occur some time it gives wrong value(eg:the actual weight is 5900Kg some time it shows 2810Kg or 2800Kg and then again convert to 5900Kg automatically it happens frequently in some timer interval).i am using timer control for getting data to textbox.
I hope i am able to clear my situation.
Thanx in advance
|
|
|
|
|
Hi I m not sure about it...
1. But some time machine will send more than 2 parameter check it Once.
2. Check Number conversion is happens...
|
|
|
|
|
thanx for your response.
But how can i check the machine sands one or two parameter.
|
|
|
|
|
You said ur using single textbox then u can try this
Use that textbox and send the set of value from machine(Raw Data) Once then u can understand the parameter and in that machine send weight with other tagged value.
|
|
|
|
|
remove the timer control,
wait for all parameters(one or two) from serial port with a particular time out.
use comport.readbuffercount
Rajesh B --> A Poor Workman Blames His Tools <--
|
|
|
|
|
I'm converting a VB6 app which has many control label arrays (95% of them contain 2 labels) with a slew of different property values (font sizes, colors, border styles, etc). I know that control arrays are not natively supported in design mode and I don't want to use the backwards comp. VB6 reference. I recreated each label at design time, but they lack an index property. Breaking out all the logic, which is very lengthy into sep property calls vs. index isn't really practical.
My question is this: is it possible in the CTOR or load to create a label array at runtime and then set each label element = to a an existing label (those created at design time). The code below obviously doesn't work, but shows what I'm trying to accomplish. Create a 2 element lbl Array which gets set to both of the correlated labels created at design time, remove the origs, and replace with label array.
I'm confused how I can set/copy all of the orig design-time label properties = to the array labels, and then destroy the origs without killing label array values (currently a pointer to an object that doesn't exist). Is it possible to loop properties on a control?
Private lblDestination(1) As Label
Private Sub frmMainForm_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
lblDestination(0) = lblDestinationTemp
lblDestination(1) = lblDestinationBottomTemp
lblDestinationTemp.Dispose()
End Sub
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
I found a way to extend the label control to include an index property.
For the sake of learning, is there a way to do the above like I was trying to do previously.
Thanks,
deez
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
I would have suggested adding the controls to a collection. It seems that adding the Index property to the control is backwards, since it doesn't know it's position in a collection, nor should it care.
|
|
|
|
|
You can loop over the controls collection using the as keyword. so if 'control' is the control value as you loop
Dim lb as Label = control as Label
I think that will work. lb will be null if the control is not a label. I am translating C# in my head here, the syntax may be wrong. But, in this way, you can find all the labels in your form and do the same thing to them.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
What you have is pretty close to what you would want. There is no reason I can think of to try to "remove the originals" as all you would be doing is setting a pointer to null. Assigning the controls to the array does not make a duplicate of the control. As for setting all the properties, you could simply loop through the array after it is created to set the properties and add event handlers. It would then look something like this:
Private lblDestination() As Label
Private Sub frmMain_Load(ByVal sender as Object, ByVal e As EventArgs) Handles MyBase.Load
'I usually create the array in a single line of code. This keeps me
'from having to know the correct number of labels when initializing the array
lblDestinations = New Label() {lblDestinationTemp, lblDestinationBottomTemp}
'set properties and event handlers
For i As Integer = 0 to lblDestinations.Length - 1
lblDestinations(i).Text = "My Label " & i.ToString()
AddHandler lblDestinations(i).Click, AddressOf LabelClick
Next
End Sub
|
|
|
|
|
I think you're right. The origs would not need to be removed because of the pointer since a true copy is not being created and memory isn't really being wasted.
Sigh. Hate when the obvious things skip by sometimes
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
I am working to add some additional functionality to a project and without changing anything to a particular form and DataSet object I began getting the error "There is already an open DataReader associated with this Command which must be closed first.". I am using a DataSet object that is actually part of the project which contains 2 datatables. I fill one for a large datagridview and fill the other table based on the row selection in the first. This has been working fine until today. I have already tried the "MultipleActiveResultSets=true;" parameter in the connection string and it makes no difference.
Resolution:
I just began setting the Dataset connection programmatically to override what was set at design time. I was using the same connection for both table adapters and after letting Ben's response sink in I realized what I was doing.
Thanks!
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
modified on Tuesday, November 25, 2008 2:57 PM
|
|
|
|
|
The message means exactly what is says; there is a DataReader created from the command's ExecuteReader() function that has not been closed. You'll have to trace through the code, find it and close it. I think it's common for this kind of thing to be done in a finally block, so maybe you inserted code to re-use a command object inside a try block where a DataReader is created from the command's ExecuteReader() function and has not been closed since the finally block hasn't executed.
Keep It Simple Stupid! (KISS)
|
|
|
|
|
If it was the code I wrote I would have all of that done but all I am doing is calling a TableDataAdapter that is created from the .NET Dataset to fill the local datatable contained in my instance of that dataset.
As I said before, this was not an issue, I did not change anything and am now having to track it down. Here is the code where it breaks.
<br />
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _<br />
Global.System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter"), _<br />
Global.System.ComponentModel.DataObjectMethodAttribute(Global.System.ComponentModel.DataObjectMethodType.Fill, false)> _<br />
Public Overloads Overridable Function GetCustomerDetailsCustomerDetailID(ByVal dataTable As CustomerDetail.CustomerDetailsDataTable, ByVal CustomerDetailID As Global.System.Nullable(Of Integer)) As Integer<br />
Me.Adapter.SelectCommand = Me.CommandCollection(1)<br />
If (CustomerDetailID.HasValue = true) Then<br />
Me.Adapter.SelectCommand.Parameters(1).Value = CType(CustomerDetailID.Value,Integer)<br />
Else<br />
Me.Adapter.SelectCommand.Parameters(1).Value = Global.System.DBNull.Value<br />
End If<br />
If (Me.ClearBeforeFill = true) Then<br />
dataTable.Clear<br />
End If<br />
Dim returnValue As Integer = Me.Adapter.Fill(dataTable)<br />
Return returnValue<br />
End Function
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
|
|
|
|
|
how can i delete a question i wrote?
|
|
|
|