Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to change display settings: screen resolution, screen refresh rate
Enumerating data formats currently available on the clipboard
Custom GDI+ class
Mapping and disconnecting network drives
Winsock: retrieving directory listing from an FTP server using passive data connection (FTP, port 21)
Capturing keyboard activity of another application with the Raw Input API (VFP9)
Winsock: sending email messages (SMTP, port 25)
How to display the Properties dialog box for a file (ShellExecuteEx)
Disk in drive A:
Using Font and Text functions
Detecting changes in connections to removable drives (VFP9)
How to download a file from the FTP server using FtpGetFile
Enumerating raw input devices attached to the system (keyboard, mouse, human interface device)
How to play AVI file on the _screen
Using EnumPrinters function to enumerate locally installed printers
Using Video Capture: displaying on FoxPro form frames and previewing video obtained from a digital camera
Running MSDOS Shell as a child process with redirected input and output (smarter RUN command)
Splash Screen for the VFP application
Subclassing CommandButton control to create BackColor property
Creating irregularly shaped FoxPro form using transparency color key
Vertical Label control
Converting Unicode data from the Clipboard to a character string using a given code page
Creating a console window for Visual FoxPro application
Enumerating network resources
Building a tree of subdirectories for a given path using FindFile functions

User rating: 9/10 (2 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Versions:
click to open
Before you begin:
This code stores into a cursor path and size data for all subdirectories within a specified path.

 
using System;
using System.Collections;
using System.IO;
 
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                DriveInfo[] allDrives = DriveInfo.GetDrives();
 
                //enumerates top level of subfolders on C:
                //sorted by NM=names, DC=create, DA=access, DW=write
                EnumFolders(allDrives[0], "NM");
            }
            catch (IOException ex)
            {
                Console.WriteLine(
                    "IO Exception: " + ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine(
                    "Exception: " + ex.Message);
            }
 
            Console.ReadKey();
        }
 
        //compares two directories using names or dates
        class DirectoryInfoComparer : IComparer
        {
            protected string compareMode;
            public DirectoryInfoComparer(string _compareMode)
            {
                compareMode = _compareMode;
            }
 
            #region IComparer Members
 
            public int Compare(object x, object y)
            {
                DirectoryInfo d1 = x as DirectoryInfo;
                if (d1 == null) throw new InvalidCastException();
 
                DirectoryInfo d2 = y as DirectoryInfo;
                if (d2 == null) throw new InvalidCastException();
 
                switch (compareMode)
                {
                    case "DC":
                        return DateTime.Compare(
                            d1.CreationTime, d2.CreationTime);
                    case "DA":
                        return DateTime.Compare(
                            d1.LastAccessTime, d2.LastAccessTime);
                    case "DW":
                        return DateTime.Compare(
                            d1.LastWriteTime, d2.LastWriteTime);
                    case "NM":
                        return string.Compare(
                            d1.FullName, d2.FullName);
                    default:
                        throw new ArgumentException();
                }
            }
 
            #endregion
        }
 
        static void EnumFolders(DriveInfo di, string sortMode)
        {
            DirectoryInfo rootInfo = 
                new DirectoryInfo(di.RootDirectory.ToString());
 
            //enumerating subdirectories on the top level
            DirectoryInfo[] subDirs = 
                rootInfo.GetDirectories();
 
            //sorting subdirectories
            Array.Sort(subDirs, new DirectoryInfoComparer(sortMode));
 
            //dispaying list of subdirectories
            foreach (DirectoryInfo subDir in subDirs)
            {
                Console.WriteLine(subDir.FullName.PadRight(40) + 
                    subDir.CreationTime.ToUniversalTime());
            }
        }
    }
}
 

User rating: 9/10 (2 votes)
Rate this code sample:
  • ~
2990 bytes  
Created: 2001-12-28 18:46:58  
Modified: 2011-12-10 09:20:22  
Visits in 7 days: 51  
Listed functions:
CompareFileTime
FileTimeToSystemTime
FindClose
FindFirstFile
FindNextFile
Printer friendly API declarations
My comment:
The last write time retrieved in this code is the UTC value, so it can be different from the local time on your computer. Use the GetTimeZoneInformation to get the constant difference in minutes between both times.

The most but not all the data returned in WIN32_FIND_DATA structures can also be retrieved by calling ADIR() function.

* * *
Also IShellFolder::EnumObjects can be used to enumerate file system folders, as well as other types of folders and objects in the system -- for example, special folders, printers, subfolders inside a compressed (zipped) folder.
Word Index links for this example:
Translate this page:
  Spanish    Portuguese    German    French    Italian  
FreeTranslation.com offers instant, free translations of text or web pages.
User Contributed Notes:
Bob | 2005-07-23 23:01:05
Hi,

I tried this code and it does not generate folders that have periods in them

bobstranks@telus.net

thx
A.M. | 2005-07-24 06:43:41
Hi Bob,

I fixed the code, it's working now as suggested.
tsoda | 2007-02-07 12:21:21
Is there an example for finding the location of a specific filename from within a container of many folders?
A.M. | 2007-02-07 13:11:54
There's no such example, unfortunately, in this reference. As far as I know, NTFS and FAT systems do not support a single location or object that stores names of all files and folders.

http://en.wikipedia.org/wiki/WinFS

Copyright © 2001-2013 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

Privacy policy
Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (23.22.212.158)
1.96 hrs.Function: 'EnumPorts'
2.77 hrs.Function: 'GdipGetImageWidth'
5.03 hrs.Function: 'SQLTables'
Function group: 'ODBC API'
9.65 hrs.Example: 'Extended MessageBox Class'
 Function: 'BeginUpdateResource'
9.66 hrs.Example: 'Using FrameRgn for displaying system colors'
16.03 hrs.Example: 'How to write and read Window Properties for the specified window'
 Example: 'Retrieving a universal form for the drive-based path for a network resource'
17.68 hrs.Function: 'NetFileGetInfo'
 Example: 'How to retrieve list of system DSNs (Data Source Name) with parameters'
Google
Advertise here!