Ana içeriğe atla


iSearch etiketine sahip yayınlar gösteriliyor

When a method calls itself

This you can't do in RPG - have a method call itself. Sounds like something you would never use? Think again. See this small console program that recurses through directories to get a list of folders and files. When the method finds a directory, it calls itself with the sub folder as a parameter whereupon the File part of the IF statement is executed. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Recurse(@"c:\temp"); } public static void Recurse(string directory) { DirectoryInfo path = new DirectoryInfo(directory); FileSystemInfo[] files = path.GetFileSystemInfos( ); foreach (FileSystemInfo file in files) { if (file is DirectoryInfo) { Console.WriteLine("Folder-> " + ((DirectoryInf

Read, write and delete files in windows

Sooner or later you'll need to access files from the Window's file system. You'll need to check if a file exists, delete it, move it , you'll need to read and write to it and upload data from it to an iSeries table etc. To illustrate how easy this is, I've included a full C# project. This program cleans up a desktop. It moves unwanted items automatically to a 'clean up' folder automatically. Items you don't want to remove are maintained in a text file manually. This file is in 'CleanUp' on your desktop after you run it the first time. Set it up to run in 'scheduled tasks' to run daily. My desktop gets absolutely splattered with downloads, images, files etc. etc. Now it gets cleaned automatically and the stuff I want to keep is always there. Files are moved but not folders. The app demonstrates two things. How to access the windows file system How to write a RPG-like app in C#. i.e. in a procedural way There is a 'main', an init et