hi. im actually making a desktop cleaner that can move the files and icons to a folder inside the listview box.
i can make the listview box filled with files contains at the desktop
and i can make a new folder which suppose to be move the files on that folder
i have 3 problems:
1. is how to get last access time of the FILE and put it column2 of the listview
2. i want to view that are unused icon and document last week, 2weeks, 1month and 2months by selecting at the combobox
3. how to move checkeditems file in listbox to a folder?
i've been researching for 2 days and not posting a topic and now im frustrated
help me.. thanks in advance.
[CODE]
Imports System.Runtime.InteropServices 'For APIs
Imports System.IO 'Import System.IO For File Operations
Imports Microsoft.Win32 'The Registry stuff
Imports System.Windows.Forms.Application
Imports System
'TO view files inside the listbox
Public Class Form1
Private Filenames() As String
Private Sub LoadFilenames()
Dim Desktop As String = My.Computer.FileSystem.SpecialDirectories.Desktop.ToString()
Dim FilePath As String
Dim NumFiles As Integer
Dim TruncName As String
For Each FilePath In Directory.GetFiles(Desktop)
TruncName = FilePath.Substring(FilePath.LastIndexOf("\") + 1) 'Remove Path From Name
ListView1.Items.Add(TruncName)
ReDim Preserve ScreenNames(NumFiles)
FileNames(NumFiles) = FilePath
NumFiles = NumFiles + 1 'Increment File Count
Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoadFilenames()
End Sub
TO CREATE A FOLDER ON DESKTOP
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Desktop As String = My.Computer.FileSystem.SpecialDirectories.Desktop
If Not My.Computer.FileSystem.DirectoryExists(Desktop & "\Unused Desktop Icon and Documents") Then
My.Computer.FileSystem.CreateDirectory(Desktop & "\Unused Desktop Icon and Documents")
End If
With Me.ListView1
For i As Integer = 0 To .CheckedItems.Count - 1
.Items.Remove(.CheckedItems(0))
Next i
End With
' If di.Exists Then
' Indicate that it already exists.
' MsgBox("That path exists already.")
' Else
' Try to create the directory.
' di.Create()
' End If
'TextBox1.Text = di.FullName
End Sub
[/CODE]
Loading
Mikko CarlosPosted Jun 26, 2008, 4:07 AM
1&2. i'm trying to view the dateaccesstime on a column inside the listview1 and compare it today.
some of my files have dates but others none.
http://www.codeguru.com/forum/archive/index.php/t-417770.html
here's the link i found by viewing filename,file types, icons, and lastdateaccess but they are in treeview1 and listview1 combo. while selecting the treeview folders the listview will automatically diplay its properties and date.
mine is different. the files on the desktop will automatically view all its properties on the listviewbox in form_load. some files have no date.
3. i tried the file.move. but there is something missing. because while im checking the files inside the listview they won't move to a folder. it's like when you checked it they are not automatically stored. is there a code to store data if it checked?
thanks.
Jan MontanoPosted Jun 25, 2008, 10:46 PM
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim filename As String
Dim lastAccessTime As DateTime
filename = "C:\boot.ini"
lastAccessTime = GetFileLastAccessTime(New FileInfo(filename))
End Sub
Private Function GetFileLastAccessTime(ByVal fsi As FileSystemInfo) As DateTime
Return fsi.LastAccessTime
End Function
2. you could also use the lastaccess time and compare it with the current date. to get your 2 months,1 month and so on...
3.
*EDIT: on the other hand you could just use the File class
1. & 2.) lastAccessTime = File.GetLastAccessTime(filename);
3.) File.move("C:\boot.ini","C:\folder\boot.ini")