[File operations] rename a file and check whether the file is occupied

Source: Internet
Author: User
File rename

C # is a function without file rename. Generally, file. Remove () is used to rename, that is, file movement.

File. Remove (oldfilefullpath, newfilefullpath)
Do not change the path. Only change the file name.

For example:

File. Move ("d :\\ New Folder \ oldpicture.bmp", "d :\\ New Folder \ newpicture.bmp ");

If the path is not changed, the file data will not be moved, so that the size of the files is the same. The function is to rename the file!

 

Check whether the file is occupied

 

File. Remove (oldfilefullpath, newfilefullpath)

 

Make newfilefullpath equal to oldfilefullpath

 

For example:
Try
{
File. Move ("d :\\ New Folder \ textpicture.bmp", "d :\\ New Folder \ textpicture.bmp ");
}
Catch (exception ex)
{
MessageBox. Show (ex. Message );
}

 

If the file is in use, an error is reported. If the file is not in use, the file name will be the same because of the prefix and backend paths, and the file name will not change!
This allows you to check whether a file is occupied.

 

Csdn Link

 

Http://topic.csdn.net/u/20080819/15/4234292e-c4d9-4e29-b5b2-8ed2e352e54d.html? Seed = 1249513417

 

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.