|
Christian Graus wrote: Sadly, the answer is 'one at a time'. Directory.GetFiles will tell you the files, then you delete them one at a time.
Does that mean that I couldnt create a program that could clean the computer like CCleaner for example?
|
|
|
|
|
No, of course not. Why would it mean that ?
Christian Graus - C++ MVP
|
|
|
|
|
|
If you want to delete all the files in a folder, the best approach would be to use a for/next statement. use a listbox for your display as oppose to a textbox.
Dim di as new system.io.directoryinfo = "your directory" '(1)
Dim fi as system.io.fileinfo
for each fi in di.getfiles'(5)
'(4)
listbox1.items.add(fi.filename)
fi.delete '(2) (3)
'(4)
next
Note:
(1) You could use a folder browser dialog to establish the folder or for the user to establish the folder
(2) When testing, have a test folder filled with copies files or something.
(3) If you wished to display first then give the option of deleting, you could put a similar for/next statement under a button's click action or something and only have delete option.
(4) You could have an if statement here for certain paremeters
(5) In the brackets after getfiles, you can specify file type
Posted by The ANZAC
|
|
|
|
|
Cool, well thanks guys for all your help, I will fiddle about with the code and see what the result is
|
|
|
|
|
I need to present an image file image in Access based on a 'file path and name' pointer in a database record. I am using OLE and I get one of two run-time error messages at the acOLECreateLink action. The first: (2793) "Microsoft Office Access can't perform the operation specified in the Action Property of the Visual Basic procedure you're trying to run." The second: (2786) "The OLE server doesn't support linking."
I can find nothing specific in the MSDN library. Help!
Michael J Wolfstone
It is always fun to learn new stuff!
|
|
|
|
|
When I use File.GetLastWriteTime(path) to get the date and time value of a file with a last write date of 5/8/2006 8:00a.m. the .NET 2.0 call always adds 1 to the hour so it ends up reading as 5/8/2006 9:00 a.m. How can I stop this? I need the file date to be read back exactly like the Windows explorer displays it.
|
|
|
|
|
Hi,
If the file is not on the same machine as the app, then you could check to see if the system time of both machines is set the same (especially daylight saving time).
Otherwise, if you are absolutely certain that it always adds exactly one hour you can use this:
CDate(File.GetLastWriteTime(path)).AddHours(-1)
Hope it helps,
Johan
|
|
|
|
|
No, the problem occurs because Win32 and .NET make different choices with regard to dealing with Daylight Saving Time.
For a discussion, see here:
http://blogs.msdn.com/oldnewthing/archive/2003/10/24/55413.aspx
To compensate, you have to adjust the time you use with SetLastWriteTime and GetLastWriteTime. When setting, adjust from .Net to Win32. When getting, adjust from Win32 to .NET. Here's some example code:
static DateTime AdjustTime_DotNetToWin32(DateTime time)
{
DateTime adjusted = time;
if (DateTime.Now.IsDaylightSavingTime() && !time.IsDaylightSavingTime())
adjusted = time - new System.TimeSpan(1, 0, 0);
else if (!DateTime.Now.IsDaylightSavingTime() && time.IsDaylightSavingTime())
adjusted = time + new System.TimeSpan(1, 0, 0);
return adjusted;
}
static DateTime AdjustTime_Win32ToDotNet(DateTime time)
{
DateTime adjusted = time;
if (DateTime.Now.IsDaylightSavingTime() && !time.IsDaylightSavingTime())
adjusted = time + new System.TimeSpan(1, 0, 0);
else if (!DateTime.Now.IsDaylightSavingTime() && time.IsDaylightSavingTime())
adjusted = time - new System.TimeSpan(1, 0, 0);
return adjusted;
}
void MySetLastWriteTime(String targetFile, DateTime t)
{
DateTime adjusted = AdjustTime_DotNetToWin32(t);
System.IO.File.SetLastWriteTime(targetFile, adjusted);
}
DateTime MyGetLastWriteTime(String targetFile)
{
DateTime t = System.IO.File.GetLastWriteTime(targetFile);
return AdjustTime_Win32ToDotNet(t);
}
|
|
|
|
|
Hi
I'm designing an interface with navigation bar ,, it's viewing my own control on the same form ,,, but i want to chech if the control is aleady viewed to prevent the user from open it more than one time ..
jooooo
|
|
|
|
|
Create a static variable, so it's visible across all instances of the control, and set it to true when the first one is shown. If it's true, don't allow more to be created.
Christian Graus - C++ MVP
|
|
|
|
|
|
*grin* not sure if I earned all of that, but sure glad to help.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I have a CheckedListBox (CLB) on my form, the user can add, edit and remove items. I also have a context menu for the CLB that has the option to remove all checked items. What i need to know is how to structure a for next statement to cycle through and remove all checked items.
Posted by The ANZAC
|
|
|
|
|
For i As Integer = 0 To CLB.Items.Count - 1<br />
CLB.SetItemChecked(i, False)<br />
Next
|
|
|
|
|
Hey ANZAC,
I'm not sure if you mean remove the item or uncheck it, but if you want to remove an item try:
For i As Integer = YourCHB.CheckedIndices.Count - 1 To 0 Step -1
YourCHB.Items.RemoveAt(YourCHB.CheckedIndices.Item(i))
Next
The reason why I am using CheckedIndices is because when I give i to Item, it knows I want the checked item index rather than the general index.
I did think of using the GetEnumerator method on CheckedIndices and going through the collection that way, but because I modify the collection, it would stuff that up, which is why I'm going backwards because the positions are getting changed on each remove.
|
|
|
|
|
Thanks, i should have stated, i am trying to remove all of the checked items, this will probably work, but i figured it out anyways.
Dim C As Integer = clbList.Items.Count
If Me.clbList.CheckedIndices.Count > 0 Then
Do Until C = 0
If clbList.CheckedIndices.Contains(C) Then
clbList.Items.RemoveAt(C)
Me.clbList.SelectedIndex = 0
End If
C -= 1
Loop
If clbList.CheckedIndices.Contains(Me.clbList.SelectedIndex) Then
Me.clbList.Items.RemoveAt(Me.clbList.SelectedIndex)
End If
End If
This is my method, not as clean but i like it well enough.
Posted by The ANZAC
|
|
|
|
|
Hi!
Is there a way to draw line and bar chart on the same chart using AxMSCHART?
or
Is there a way to do paint both Bar and line graph on a PictureBox?
Or
Draw BarGraph on one Picturebox and Line on another picturebox,make one of them transparent so it would expose the other graph that is located right beneath.
|
|
|
|
|
If you want to do graphics programming, you need to forget about using picture boxes, so you can just draw it yourself.
Christian Graus - C++ MVP
|
|
|
|
|
Hi everyone!
I trying to write a app to do some chinese->english translation using google. I have all the code down to generate the right URL, i.e.
http://translate.google.com/translate_t?text=%E4%BD%A0%E5%A5%BD&hl=en&langpair=zh-CN|en&tbb=1&ie=utf-8
I can paste that into a browser and it works, but when I try to request the page using msxml 6.0 I get a 403 error (forbidden). I tried requesting "www.google.com" first, thinking maybe I need a cookie, and google.com returns fine, but still when I go on to the translate url I get the 403. Is there anyway around this, maybe changing my request header?
I also tried another approach with the WebBrowser control. I had a little more success using it; the page gets returned with no 403, but, well hard to explain unless you look at this page:
http://translate.google.com/transla...&tbb=1&ie=utf-8
so if you put that in your browser, you see ?? (or chinese characters if you have the language pack installed) in the 'Original Text:' box, and "Hello" as the translation. However, when I use this same URL in the webbrowser control of vb.net the returned page has ?? as the 'Original Text:' and "-" as the translated text.
Now this is really making me go bonkers. Anyone tell me what the heck is going on? I will bow down if you help me through this
-Josh K.
Co-Founder/VP
www.GamerWealth.com
|
|
|
|
|
hi there,
How can we use resource file to implement multi language in our program?
please help
Syed Shahid Hussain
|
|
|
|
|
|
Really Thanks Friend.
Syed Shahid Hussain
|
|
|
|
|
Hi I am trying to open a web page in a new browser window, I can easily open a page in the last used window:
System.Diagnostics.Process.Start("http://www.google.com")
But I would like to have it opened in a new window.
Any suggestions?
Kevin
|
|
|
|
|
If the page opens in the last window, in a new window or in a new tab depends on the settings in the browser.
---
b { font-weight: normal; }
|
|
|
|