By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,847 Members | 2,354 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,847 IT Pros & Developers. It's quick & easy.

how to move checkeditems file in listbox to a folder?

P: 3
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.

Expand|Select|Wrap|Line Numbers
  1. Imports System.Runtime.InteropServices 'For APIs
  2. Imports System.IO 'Import System.IO For File Operations 
  3. Imports Microsoft.Win32 'The Registry stuff
  4. Imports System.Windows.Forms.Application
  5. Imports System
  6.  
  7.  
  8.  
  9. 'TO view files inside the listbox
  10.  
  11. Public Class Form1
  12.  
  13.     Private Filenames() As String
  14.  
  15.     Private Sub LoadFilenames()
  16.  
  17.         Dim Desktop As String = My.Computer.FileSystem.SpecialDirectories.Desktop.ToString()
  18.         Dim FilePath As String 
  19.         Dim NumFiles As Integer 
  20.         Dim TruncName As String 
  21.  
  22.         For Each FilePath In Directory.GetFiles(Desktop)
  23.  
  24.             TruncName = FilePath.Substring(FilePath.LastIndexOf("\") + 1) 'Remove Path From Name
  25.  
  26.  
  27.             ListView1.Items.Add(TruncName)
  28.  
  29.  
  30.             ReDim Preserve ScreenNames(NumFiles) 
  31.  
  32.             FileNames(NumFiles) = FilePath 
  33.  
  34.             NumFiles = NumFiles + 1 'Increment File Count
  35.  
  36.  
  37.  
  38.         Next
  39.  
  40.     End Sub
  41.  
  42.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  43.         LoadFilenames()
  44.     End Sub
  45.  
  46.  
  47. TO CREATE A FOLDER ON DESKTOP
  48.  
  49.  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  50.         Dim Desktop As String = My.Computer.FileSystem.SpecialDirectories.Desktop
  51.  
  52.         If Not My.Computer.FileSystem.DirectoryExists(Desktop & "\Unused Desktop Icon and Documents") Then
  53.         My.Computer.FileSystem.CreateDirectory(Desktop & "\Unused Desktop Icon and Documents")
  54.           End If
  55.  
  56.  
  57.         With Me.ListView1
  58.             For i As Integer = 0 To .CheckedItems.Count - 1
  59.  
  60.                 .Items.Remove(.CheckedItems(0))
  61.  
  62.             Next i
  63.         End With
  64.  
  65.         ' If di.Exists Then
  66.         ' Indicate that it already exists.
  67.         ' MsgBox("That path exists already.")
  68.         ' Else
  69.         ' Try to create the directory.
  70.         ' di.Create()
  71.  
  72.         '  End If
  73.  
  74.         'TextBox1.Text = di.FullName
  75.  
  76.  
  77.     End Sub
  78.  
  79.  
  80.  
Jun 25 '08 #1
Share this Question
Share on Google+
4 Replies


Curtis Rutland
Expert 2.5K+
P: 3,256
You should look into FileInfo and DirectoryInfo. I've found them much more useful than the File and Directory objects.
Jun 25 '08 #2

P: 3
You should look into FileInfo and DirectoryInfo. I've found them much more useful than the File and Directory objects.
what's the difference of fileinfo and directoryinfo between file and directory? when i'm typing fileinfo the only extension .equals .reference equals. pls help. need some sample codes if any. thanks.
Jun 25 '08 #3

Curtis Rutland
Expert 2.5K+
P: 3,256
what's the difference of fileinfo and directoryinfo between file and directory? when i'm typing fileinfo the only extension .equals .reference equals. pls help. need some sample codes if any. thanks.
Here are a few very quick samples of what you can do with the FileInfo and DirectoryInfo classes:
Expand|Select|Wrap|Line Numbers
  1.         Dim d As New System.IO.DirectoryInfo("path")
  2.         Dim fArray As System.IO.FileInfo()
  3.         'gets all files with/without filter
  4.         fArray = d.GetFiles("*.txt")
  5.  
  6.         Dim f As New System.IO.FileInfo("filePath")
  7.         Dim lastAccesed As DateTime
  8.         'last accessed time 
  9.         lastAccesed = f.LastAccessTime
  10.  
Jun 25 '08 #4

P: 3
Here are a few very quick samples of what you can do with the FileInfo and DirectoryInfo classes:
Expand|Select|Wrap|Line Numbers
  1.         Dim d As New System.IO.DirectoryInfo("path")
  2.         Dim fArray As System.IO.FileInfo()
  3.         'gets all files with/without filter
  4.         fArray = d.GetFiles("*.txt")
  5.  
  6.         Dim f As New System.IO.FileInfo("filePath")
  7.         Dim lastAccesed As DateTime
  8.         'last accessed time 
  9.         lastAccesed = f.LastAccessTime
  10.  
how about #3? when i checked some files in the listview1. when i hit the button the file that i checked will be move to another folder? is it possible to store data when it checked? thanks for helping me.
Jun 26 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.