Windows Get File status

Source: Internet
Author: User

Before you manipulate a file, you want to get the status of the current file, avoid opening the file again, the Code reference network has been written, shared with yourself as a record, but also as a reference for others.

    #regionGet file Status[DllImport ("Kernel32.dll")]    Private Static externIntPtr _lopen (stringLppathname,intireadwrite); [DllImport ("Kernel32.dll")]    Private Static extern BOOLCloseHandle (IntPtr hobject); Private Const intOf_readwrite=2; Private Const intOf_share_deny_none=0x40; Private Static ReadOnlyIntPtr hfile_error=NewINTPTR (-1); Private Static intGetfilestatus (stringfilefullname) {      if(!file.exists (Filefullname)) {        return-1;//File NOT exists} INTPTR handle=_lopen (filefullname,of_readwrite|Of_share_deny_none); if(handle==hfile_error) {        return 1;//Aready Open} closehandle (handle); return 0;//Not Open    }    #endregion

You need to reference a namespace:

using System.Runtime.InteropServices;

Windows Get File status

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.