Cocoa: If Directory contains File?

FusionGamerFusionGamer USMember

I'm porting the Reggie! Level Editor to C# as a learning experience, and seem to be stuck on how I would scan the selected directory for 01-01.

How would I scan a directory for files? Thanks,
Shane.

Posts

  • SKallSKall USMember ✭✭✭✭
    edited March 2014

    You can use DirectoryInfo and call GetFiles() to get the file info. Here is a recursive file scan from the current application directory:

        public override void FinishedLaunching(NSObject notification)
        {
            mainWindowController = new MainWindowController ();
            mainWindowController.Window.MakeKeyAndOrderFront (this);
    
            ScanDirectory(new DirectoryInfo (Environment.CurrentDirectory));
        }
    
        static void ScanDirectory(DirectoryInfo di)
        {
            foreach (var file in di.GetFiles())
            {
                System.Diagnostics.Debug.WriteLine (file.FullName);
            }
    
            foreach (var dir in di.GetDirectories())
            {
                ScanDirectory (dir);
            }
        }
    
Sign In or Register to comment.