A scheme for managing files or directories using the ASP.net program

Source: Internet
Author: User
Tags bool file copy
Asp.net| Program There are a number of ways to manage files or directories using the ASP.net program, such as Directory.createdirectory,directoryinfo.create to create a directory, but today we introduce another alternative way to create a directory, which is to use the cmd command To manage.


People who have used DOS commands know that DOS commands can do a lot of things, such as Dir can enumerate files and subdirectories in a directory. This time, we use the ASP.net program to invoke CMD's command to manage the file.
Here's how to call Cmd.exe:
public bool cmd (string argm)
{
Start creating files
Process P = new process ();
p.StartInfo.FileName = "cmd.exe";
P.startinfo.useshellexecute = false;
P.startinfo.redirectstandardinput = true;
P.startinfo.redirectstandardoutput = true;
P.startinfo.redirectstandarderror = true;
P.startinfo.createnowindow = true;


Try
{
P.start ();
P.standardinput.writeline (ARGM);
P.standardinput.writeline ("Exit");
P.standardoutput.readtoend ();
P.close ();
return true;
}
Catch
{
return false;
}
}
Where ARGM is to represent the execution of the cmd command, such as I want to create a folder, using the following methods:
BOOL created = cmd (@ "MD e:\abc\mydir");


The commands for file management using CMD are as follows: Creating a folder MD
Delete Folder Rd
Delete File Del
Rename folder move
Renaming files Rename
Replication Folder xcopy
Copy file copy
Move a file or folder



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.