C # file operation statement:
// Check whether the file exists File. exists ( @" C: \ My Folder \ filename " ); Try {File. Delete ( @" C: \ jihua.cnblogs.com.txt " );} Catch {MessageBox. Show ( " Deletion failed " , " Jihua.cnblogs.com " );} Try {File. Create ( @" C: \ jihua.cnblogs.com.txt " );} Catch {MessageBox. Show ( " Creation failed " , " Jihua.cnblogs.com " );} Try {File. Move ( @" C: \ jihua.cnblogs.com.txt " , @" C: \ new.jihua.cnblogs.com.txt " );} Catch {MessageBox. Show ( " Failed to move " , " Jihua.cnblogs.com " );}
C # folder operation statement:
Bool Exists = directory. exists ( @" C: \ my folder " ); // Check whether the folder exists Try {Directory. Delete ( @" C: \ my folder " );} Catch {MessageBox. Show ( " Deletion failed " , " Jihua.cnblogs.com " );} Try {Directory. createdirectory (@" C: \ my folder " );} Catch {MessageBox. Show ( " Creation failed " , " Jihua.cnblogs.com " );} Try {Directory. Move ( @" C: \ my folder " , @" D: \ Folder " );} Catch {MessageBox. Show ( " Failed to move " , " Jihua.cnblogs.com " );}
remember to reference the system. Io namespace