|
-
Nov 29th, 2016, 03:40 PM
#6
Re: Counting Problem
I thought it would be best to point out an issue... in post #1 this is part of your code:
Code:
Environment.SpecialFolder.Windows & "Temp/"
Assuming Environment.SpecialFolder.Windows returns "C:\Windows", the overall result will be "C:\WindowsTemp/", which has two problems - not only is it missing the \ in between the folder names (thus looks for WindowsTemp instead), but you have / at the end which is not valid, and will presumably cause issues (while Windows will allow you to incorrectly use / in some situations, using a mixture of \ and / is much more likely to fail).
 Originally Posted by jmiller1225
Hey thanks for the help this seems to be the trick to get it to work
Code:
Option Strict On
Option Infer Off
Imports System.IO
Imports System.Collections.Generic
Imports System.Linq
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Windows As String = Environment.GetFolderPath(Environment.SpecialFolder.Windows)
Dim UserProfile As String = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
Dim counter1 As Integer = Directory.GetFiles(Windows & "\Temp\", "*.*", SearchOption.AllDirectories).Count
Dim counter2 As Integer = Directory.GetFiles(UserProfile & "\AppData\Local\Packages\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\AC\", "*.*", SearchOption.AllDirectories).Count
MsgBox("Number of files is : " & counter1 + counter2)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class
Note that the location of "special" folders can change over time (even on the same computer and version of Windows), and they tend to be named using the language that Windows is defined to use.
As such, attempting to build a path to one (as you did with Windows & "\Temp\" ) is unreliable. If there is a full location available (such as My.Computer.FileSystem.SpecialDirectories.Temp or Environment.SpecialFolder.LocalApplicationData ) then it is best to use it.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|