473,836 Members | 1,500 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Microsoft Scripting Runtime #2

ADezii
8,834 Recognized Expert Expert
This is the 2nd Tip in a series of Tips on the Microsoft Scripting Runtime Library. The 1st Tip related to Drives, while this Tip will concentrate on the Folders (Directories) in your PC and various methods to retrieve information from and how to manipulate them. The code should be self explanatory and basically documents itself. Should there be any questions related to this Topic, please feel free to ask.
Expand|Select|Wrap|Line Numbers
  1. 'Accessing Folder Properties
  2. Dim fso As FileSystemObject, fldr As Folder
  3. Set fso = New Scripting.FileSystemObject    'OR
  4. 'Set fso = CreateObject("Scripting.FileSystemObject")
  5.  
  6. 'Creates an Instance of a Folder
  7. Set fldr = fso.GetFolder("C:\Windows\System32")
  8.  
  9. Debug.Print "Folder Properties of " & fldr.Path
  10. Debug.Print "  Folder Name: " & fldr.Name
  11. Debug.Print "  Folder Size: " & FormatNumber(fldr.Size, 0, vbFalse, vbFalse, vbTrue) & " bytes"
  12. Debug.Print "  Folder Created: " & fldr.DateCreated
  13. Debug.Print "  Folder Path: " & fldr.Path
  14. Debug.Print "  Folder Last Modified: " & fldr.DateLastModified
  15. Debug.Print "  Folder Last Accessed: " & fldr.DateLastAccessed
  16. Debug.Print "  Folder Drive: " & fldr.Drive
  17. Debug.Print "  Files in Folder: " & FormatNumber(fldr.Files.Count, 0, vbFalse, vbFalse, vbTrue) & " files"
  18. Debug.Print "  Is this a Root Folder: " & fldr.IsRootFolder
  19. Debug.Print "  Parent Folder: " & fldr.ParentFolder
  20. Debug.Print "  Folder Path: " & fldr.Path
  21. 'Could also use the GetBaseName Method of the File System Object
  22. Debug.Print "  Folder Short Name: " & fldr.ShortName
  23. Debug.Print "  Folder Short Path: " & fldr.ShortPath
  24. Debug.Print "  Number of Sub-Folders: " & fldr.SubFolders.Count
  25. Debug.Print "  Folder Type: " & fldr.Type
  26. Debug.Print
  27.  
  28.  
  29. 'Code that creates a Temporary Folder (fso previously created)
  30. Dim msTemporaryFolder As String
  31. msTemporaryFolder = fso.GetSpecialFolder(TemporaryFolder).Path & "\"
  32. Debug.Print msTemporaryFolder
  33. Debug.Print
  34.  
  35.  
  36. 'Code to see if a Folder exists (fso previously created)
  37. 'Could also use the FolderExists Method of the File System Object
  38. If fso.FolderExists("C:\Test") Then
  39.   Debug.Print "Folder exists"
  40. Else
  41.   Debug.Print "Folder does not exist"
  42. End If
  43. Debug.Print
  44.  
  45.  
  46. 'Code to create a Folder (fso previously created)
  47. 'Could also use the CreateFolder Method of the File System Object
  48. Set fldr = fso.CreateFolder("C:\Windows\System32\Temp Extraction Area")
  49. Debug.Print "Created Folder " & fldr.Name
  50.  
  51.  
  52. 'Code to Delete a Folder (fso previously created)
  53. 'Could also use the DeleteFolder Method of the File System Object
  54. Set fldr = fso.GetFolder("C:\Folder 1\Folder 2\Folder to Delete")
  55. fldr.Delete True       '"Folder to Delete" is Deleted
  56.  
  57.  
  58. 'Code to Move a Folder (fso previously created)
  59. 'Could also use the MoveFolder Method of the File System Object
  60. Set fldr = fso.GetFolder("C:\Folder1\Folder2\Folder3")
  61. fldr.Move "C:\"     '"Folder3" moved to C:\
  62.  
  63.  
  64. 'Code to Copy a Folder (fso previously created)
  65. 'Could also use the CopyFolder Method of the File System Object
  66. Set fldr = fso.GetFolder("C:\Folder1\Folder2")
  67. fldr.Copy "C:\List", True       'Copies "Folder2" to C:\List
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. Folder Properties of C:\WINDOWS\system32
  2.   Folder Name: system32
  3.   Folder Size: 888,994,639 bytes
  4.   Folder Created: 10/1/2005 2:46:52 AM
  5.   Folder Path: C:\WINDOWS\system32
  6.   Folder Last Modified: 2/5/2008 7:04:21 PM
  7.   Folder Last Accessed: 2/5/2008 7:04:22 PM
  8.   Folder Drive: C:
  9.   Files in Folder: 2,309 files
  10.   Is this a Root Folder: False
  11.   Parent Folder: C:\WINDOWS
  12.   Folder Path: C:\WINDOWS\system32
  13.   Folder Short Name: System32
  14.   Folder Short Path: C:\Windows\System32
  15.   Number of Sub-Folders: 50
  16.   Folder Type: File Folder
  17.  
  18. C:\DOCUME~1\Armund\LOCALS~1\Temp\
  19.  
  20. Folder exists
  21.  
  22. Created Folder Temp Extraction Area
Feb 9 '08 #1
0 5162

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

Similar topics

1
4129
by: MatthewRoberts | last post by:
Howdy All, I am having difficulty with two-way communication across AppDomains in an attempt to dynamically script applications. Everything works as expected, except when using ByRef parameters. The below explanation is lengthy, but well worth the read. If you can help me, I'd gladly share this code which has greatly helped my development of extensible applications.
0
1579
by: fiona | last post by:
Catalyst Releases Scripting Editions of SocketTools Client and server-side development for Active Server Pages and PHP. Yucca Valley, CA, May 25, 2005 - Catalyst Development Corp (www.catalyst.com) - with over 10 years experience developing Internet components announced that Scripting and Secure Scripting Editions have been added to the SocketTools family of products. The Scripting Editions were designed specifically for client and...
17
4212
by: Karl Irvin | last post by:
To use the Textstream object, I had to set a Reference to the Microsoft Scripting Runtime. This works good with A2000 Is the Scripting Runtime included with A2002 and A2003 so the Reference won't be broken when my app is opened with those versions. Also is the Scripting Runtime included as part of the A2000 Runtime Engine which some of my customers use.
1
2342
by: Karl Irvin | last post by:
To use the Textstream object, I had to set a Reference to the Microsoft Scripting Runtime. This works good with A2000 Is the Scripting Runtime included with A2002 and A2003 so the Reference won't be broken when my app is opened with those versions. Also is the Scripting Runtime included as part of the A2000 Runtime Engine which some of my customers use.
14
2328
by: frostalicious | last post by:
Used VB.NET (on my client PC) to convert VB6 executable to .NET executable. Placed the .exe file on a network drive on my server. From client, ran .NET Wizards "Trust an Assembly" to make the .exe (on the network drive, on the server) "Full Trust." From the client, double-click on the ..exe (on the network drive, on the server) and it runs fine. So far, so good, but... On the server, where I've installed not VB.NET but .NET
1
1013
by: PaulieS | last post by:
Hi all. Am migrating a customer from IIS5 on W2K server to IIS6 on W2K3. Zipped all the websites and unzipped them to the identical locations on new server. Used IISMT to migrate metabase. Got this error when I tried to run a very basic page... code: <%@ LANGUAGE=vbscript %> <%
7
8864
ADezii
by: ADezii | last post by:
The next series of Tips will involve the Microsoft Scripting Runtime Library (Scrrun.dll). This Library is, in my humble opinion, one of the most useful and practical Libraries ever created. With the Scripting Runtime Library, you can retrieve information related to Drives, Folders, Files, and Text Files and set/retrieve certain Attributes of Drives, Folders, Files, and Text Files. Through Methods exposed by this Library, you can also manipulate...
0
5424
ADezii
by: ADezii | last post by:
This is the 3rd in a series of Tips dealing specifically with the Microsoft Scripting Runtime Library. In this Tip, we'll show you how to return specific Properties relating to Files, as well as various Methods to Copy, Move, and Delete them. The code is self explanatory, so I'll jump right in: Dim fso As FileSystemObject, fil As File 'Set fso = New Scripting.FileSystemObject OR Set fso = CreateObject("Scripting.FileSystemObject") ...
0
4470
ADezii
by: ADezii | last post by:
This is the last in a series of Tips involving the Microsoft Scripting Runtime Library and deals with creating, opening, writing to, reading from, and closing Text Files via this Library. At this time, the Scripting Library cannot deal with the opening and manipulation of Files in Binary Mode, so we will only demonstrate this functionality as it relates to Text Files. The code is fairly straightforward and sparsely commented, so I will not bore...
0
9671
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10595
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9379
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6979
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5650
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5828
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4458
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4021
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.