Results 1 to 9 of 9

Thread: Retrieving Folder Size

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2010
    Posts
    4

    Retrieving Folder Size

    Hello All,

    I'm teaching myself some VB and decided the best way was to just dive in and start developing some useful personal apps. However, I am running into an issue when retrieving a folder size.

    'This does not work when I insert %TMP%, If I insert an actual path like C:\Temp, it works fine.
    objFolder = objFSO.GetFolder("%TMP%")

    Am I missing an import or something? I currently have no imports. Any help would be appreciated.

  2. #2
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Retrieving Folder Size

    There is no path called %TMP%
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2010
    Posts
    4

    Re: Retrieving Folder Size

    Quote Originally Posted by weirddemon View Post
    There is no path called %TMP%
    Not True, There is an environmental variable path for %TMP% and %TEMP%. The problem is I do not think "program" can interperate the environmental variables because I am doing something wrong.

  4. #4
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Retrieving Folder Size

    Quote Originally Posted by Infatuas View Post
    Not True, There is an environmental variable path for %TMP% and %TEMP%. The problem is I do not think "program" can interperate the environmental variables because I am doing something wrong.
    No. You are incorrect. I'll say it again. There is no path called %TMP% or %TEMP%. An environmental variable is not a path. In the code you're using, its asking for an absolute path, not an environmental variable.

    In your code you say, "here's the path I want you to look at", it looks at that path and finds nothing, because it isn't a path. You're telling it to look for a path, not an environmental variable.

    If you want to use the latter, then specify it. I'm not at my computer, so I cant whip up an example. But if you look it up in MSDN (which is where you should always start) you'll be able to figure out how to use environmental variables in VB fairly quickly.
    Last edited by weirddemon; Dec 29th, 2010 at 01:11 AM.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2010
    Posts
    4

    Re: Retrieving Folder Size

    As I stated above, TMP is an environmental variable that I had to string out within Environ("TMP"). Problem Solved.

    Dim tmpPATH As String
    tmpPATH = Environ("TMP")
    objFSO = CreateObject("Scripting.FileSystemObject")
    objFolder = objFSO.GetFolder(tmpPATH)

  6. #6
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Retrieving Folder Size

    Quote Originally Posted by Infatuas View Post
    As I stated above, TMP is an environmental variable that I had to string out within Environ("TMP"). Problem Solved.

    Dim tmpPATH As String
    tmpPATH = Environ("TMP")
    objFSO = CreateObject("Scripting.FileSystemObject")
    objFolder = objFSO.GetFolder(tmpPATH)
    If you want to learn the language, then listen to what I'm saying and don't assume you know what you're talking about. If you did, you wouldnt be here.

    Like I said, an environmental variable is NOT a path. It's an environmental variable. Which is why you used Environ to get it to work.

    In the code you first used, you told the app to look for an absolute path and nothing more. By using Environ, your're now telling it to look for an environmental variable and not a path.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  7. #7
    Fanatic Member Dnereb's Avatar
    Join Date
    Aug 2005
    Location
    Netherlands
    Posts
    863

    Re: Retrieving Folder Size

    My two cents...


    Instead of going the VB6.0 workaround way use the .NET framwork
    Like:

    Code:
    Dim FldInfo As IO.DirectoryInfo
            Dim Path As String = My.Computer.FileSystem.SpecialDirectories.Temp
            FldInfo = New DirectoryInfo(Path)
    THe specialdirectories is also the way to find the desktopfolder etc...

    Have Fun
    why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
    for every question you ask provide an answer on another thread.

  8. #8
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Retrieving Folder Size

    Quote Originally Posted by Dnereb View Post
    My two cents...


    Instead of going the VB6.0 workaround way use the .NET framwork
    Like:

    Code:
    Dim FldInfo As IO.DirectoryInfo
            Dim Path As String = My.Computer.FileSystem.SpecialDirectories.Temp
            FldInfo = New DirectoryInfo(Path)
    THe specialdirectories is also the way to find the desktopfolder etc...

    Have Fun
    I am guessing that the OP is using FSO because it has a size property for an entire folder.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  9. #9

    Thread Starter
    New Member
    Join Date
    Dec 2010
    Posts
    4

    Re: Retrieving Folder Size

    Quote Originally Posted by weirddemon View Post
    If you want to learn the language, then listen to what I'm saying and don't assume you know what you're talking about. If you did, you wouldnt be here.

    Like I said, an environmental variable is NOT a path. It's an environmental variable. Which is why you used Environ to get it to work.

    In the code you first used, you told the app to look for an absolute path and nothing more. By using Environ, your're now telling it to look for an environmental variable and not a path.
    Now, this would have been a better suited initial response from you if you had full intensions of "training" someone with explanation and not just stating, "Path doens't exist". Thank you anyways.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width