MOCKSTACKS
EN
Questions And Answers

More Tutorials









Manipulating files and directories



Manipulating files and directories

The action of opening a file for writing creates it. Perl also provides functions to manipulate files without having to ask the operating system to do it.

unlink(filename)

Delete an existing file. Unlink can take a list of files, or wildcard as an argument as well: unlink(<*.bak>)

rename(oldname, newname) This function renames a file. It is possible to move files into other directories by specifying a path as part of the new name.

Directories also have some special function associated with them

mkdir(dirname, mode)
Create a new directory. The “mode” specifies the permissions (set this to 0777 to be safe).

rmdir(dirname)
Removes (empty) directories

chdir(dirname)
Change current working directory to dirname

File and directory attributes can be modified as well:

chmod(permission, list of files)
Change the permissions of files or directories:
666 = read and write
444 = read only
777 = read, write, and executable

utime(atime, mtime, list of files)

Modify timestamps on files or directories. “atime” is the time of the most recent access, and “mtime” is the time the file/directory was last modified.


Conclusion

In this page (written and validated by ) you learned about Perl Manipulating files and directories . What's Next? If you are interested in completing Perl tutorial, your next topic will be learning about: Perl Modules.



Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


Share On:


Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.