Traverse subfolders and files in a folder

Source: Internet
Author: User
Tags file info

Traverse subfolders and files in a folder and compress the files

Void compression () {info = "processing... "; Directoryinfo folder = new directoryinfo (" C: \ Temp "); try {filesysteminfo [] files = folder. getfilesysteminfos (); For (INT I = 0; I <files. length; I ++) {compression (files [I]) ;}} catch (exception ex) {MessageBox. show (ex. message); return;} info = "compressed. ";} Void compression (filesysteminfo finfo) {If (! Finfo. exists) return; directoryinfo dir = finfo as directoryinfo; If (Dir! = NULL) {filesysteminfo [] files = NULL; try {files = dir. getfilesysteminfos ();} catch (exception ex) {MessageBox. show (ex. message); return ;}for (INT I = 0; I <files. length; I ++) {fileinfo file = files [I] As fileinfo; If (file! = NULL) {// is the file info = string. Format ("processing {0}", file. fullname); try {// compresses the file...} Catch {logger. error (string. format ("processing {0} failed", file. fullname) ;}} else {compression (files [I]) ;}} else {fileinfo file = finfo as fileinfo; Info = string. format ("processing {0}", file. fullname); try {// compress the file...} Catch {logger. Error (string. Format ("processing {0} failed", file. fullname ));}}}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.