C # Technology Accumulation (unzip the tar file, parse the XML, rename the file, delete the file)

Source: Internet
Author: User

Because the business needs to write a small program recently, to share:


First say the background, I call center system Management, weekly will export a batch of audio files to customer quality inspection. Recording is directly downloaded from the server copy, a number of recordings have thousands, and the original export of the recording a little ' two ' can not let people get the ins and outs. That's what this is about.

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M00/82/C4/wKiom1dgtvLw1UkwAAAq0f-BhUg049.png-wh_500x0-wm_3 -wmp_4-s_3449413215.png "style=" Float:none; "title=" 1.png "alt=" Wkiom1dgtvlw1ukwaaaq0f-bhug049.png-wh_50 "/>

After the decompression is the case, each recording has an XML explanation file, the file name and the same as the record file name. These file names feel like they're piled up with time stamps.

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/82/C4/wKiom1dgtvPiTbHYAAB7ivLzBqU993.png-wh_500x0-wm_3 -wmp_4-s_2075224744.png "style=" Float:none; "title=" 2.png "alt=" Wkiom1dgtvpitbhyaab7ivlzbqu993.png-wh_50 "/>

The XML explanation document has the Callid, the call number, the call time and so on N more information. The customer requests to compress all the recording files a package, and the file name is used for the power number + time name, so as to facilitate viewing.

Background requirements are complete.

Analysis Solution: First, the TAR is the compression package under Linux, need to decompress, but also batch processing, and then read the XML document information, the incoming call number and call time to form a new file name, and then the original recording file renamed, but also batch processing.

The analysis is complete.


At first, I want to use Python (recently learning, not familiar) to solve, give up; C + + is also two knives, afraid to miss the time; Finally, I use C # to do a simple small program, after all, still familiar with the faster.


Download the DLL file from the Internet ' SharpZipLib.dll ', which contains zip,rar,tar compression and decompression of a lot of things, thank you for providing this stuff.


There is a lot of code here, just search can see ~ ~ ~


Read the XML file information, C # System.Xml is very good stuff.

public static Recordinginfo Getrecordinginfo (String xmlfilename)

{

Recordinginfo rdinfo=new recordinginfo ();

String content = String. Empty;

XmlDocument xmldoc = new XmlDocument ();

Try

{

Xmldoc.load (XMLfileName); Loading an XML document

XmlNode node = xmldoc.childnodes[1];

Call time

rdinfo.stime = node. attributes["StartTime"]. Value.substring (0, 19);

Audio file name

rdinfo.oldname = node. attributes["FileName"]. Value;

Call number

Rdinfo.ani = node. Childnodes[0]. CHILDNODES[3]. CHILDNODES[7]. InnerText;

}

catch (Exception ex)

{

Throw ex; You can define your own exception handling here.

}

return rdinfo;

}


Recordinginfo is one of my classes for recording files:

public class Recordinginfo

{

public string Oldname {get; set;}

public string ANI {get; set;}

public string Stime {get; set;}

}

Then it is the name of the file and delete the original file, first to delete the file, this simple:

public bool Deletefiles (string fileName)

{

if (file.exists (fileName))

{

File.delete (FileName);

return true;

}

return false;

}

File name, first use to know C # file class did not rename this method, simply cry dead. The network is a magical thing, you do not need to remember, as long as the search, there will always be some place you need: reference to these two

Using Microsoft.VisualBasic;

Using Microsoft.VisualBasic.Devices;

The following two sentences to resolve the renaming, hahaha, you laugh, suddenly think you saw yesterday a sentence, "Why programmers like to write code, because that is in the creation of a life, to give him the program intelligence ~"

Computer MyComputer = new computer ();


MyComputer.FileSystem.RenameFile (FileName, newName);

A few key points have been solved, the rest only need to organize the code, the entire logic is organized properly OK.


Overall interface diagram:

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/82/C4/wKioL1dgv_KjSYYsAABx9_cZIio481.png-wh_500x0-wm_3 -wmp_4-s_3698903111.png "title=" 3.png "alt=" Wkiol1dgv_kjsyysaabx9_cziio481.png-wh_50 "/>

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M02/82/C5/wKiom1dgv6ewXoZXAACdsB_icw0709.png-wh_500x0-wm_3 -wmp_4-s_3753019524.png "title=" 4.png "alt=" Wkiom1dgv6ewxozxaacdsb_icw0709.png-wh_50 "/>

The extracted files are like this

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/82/C4/wKioL1dgwUODgeRAAAAtv8XRsVc863.png-wh_500x0-wm_3 -wmp_4-s_2189595128.png "title=" 5.png "alt=" Wkiol1dgwuodgeraaaatv8xrsvc863.png-wh_50 "/>

Complete, the test can be used several times.

This article is from the "Learning Diary" blog, so be sure to keep this source http://wuqiang265.blog.51cto.com/4718310/1789418

C # Technology Accumulation (unzip the tar file, parse the XML, rename the file, delete the file)

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.