Sidef

 view release on metacpan or  search on metacpan

lib/Sidef/Types/Glob/File.pod  view on Meta::CPAN


=cut

=head2 move

    file.move(destination)

Moves the file to C<destination> (a filename, or a C<File>/C<Dir> object). Returns C<true> on success, C<false> otherwise. As with L</rename>, C<self>'s own stored path is not updated.

    File("old_name.txt").move("new_name.txt")
    File("old_name.txt").move(Dir("archive"))

Aliases: I<mv>

=cut

=head2 copy

    file.copy(destination)

Copies the file to C<destination> (a filename, or a C<File>/C<Dir> object). Returns C<true> on success, C<false> otherwise.

    File("source.txt").copy("backup.txt")

Aliases: I<cp>

=cut

=head2 link

    file.link(new_name)

Creates a hard link named C<new_name> pointing to the same inode as C<file>. Returns C<true> on success, C<false> otherwise.

    File("source.txt").link("hardlink.txt")

=cut

=head2 symlink

    file.symlink(link_name)

Creates a symbolic link named C<link_name> pointing to C<file> (which doesn't need to exist yet). Returns C<true> on success, C<false> otherwise.

    File("original.txt").symlink("link_to_original")

=cut

=head2 readlink

    file.readlink

Reads the target of a symbolic link, returning it as a C<Dir> object if the target is itself a directory, or as a C<File> object otherwise. If the path isn't actually a symbolic link, the returned object wraps an undefined path rather than being C<ni...

    var target = File("shortcut").readlink

Aliases: I<read_link>

=cut

=head2 chown

    file.chown(uid, gid)

Changes the file's owner and group (as numeric IDs). Returns C<true> on success, C<false> otherwise. May require elevated privileges.

    File("data.txt").chown(1000, 1000)

=cut

=head2 chmod

    file.chmod(permission)

Changes the file's permission bits. Returns C<true> on success, C<false> otherwise.

    File("script.sh").chmod(0755)

=cut

=head2 truncate

    file.truncate(length=0)

Truncates the file to C<length> bytes (extending with null bytes if the file was shorter). Returns C<true> on success, C<false> otherwise.

    File("data.txt").truncate(100)

=cut

=head2 unlink

    file.unlink
    File.unlink(*paths)

Called on an instance, deletes just that file and returns C<true>/C<false>. Called on the C<File> class itself with a list of paths, deletes each one and returns the C<Number> of files successfully deleted (I<not> a boolean).

    File("temp.txt").unlink                     #=> true or false
    File.unlink("file1.txt", "file2.txt")       #=> a count, e.g. 2

=cut

=head2 delete

    file.delete
    File.delete(*paths)

Like L</unlink>, but called on an instance, returns C<true>/C<false>; called on the class with a list of paths, returns the count of files successfully deleted.

    File("temporary.txt").delete && say("File deleted successfully")

Aliases: I<remove>

=cut

=head1 CONVERSION

=head2 to_str

    file.to_str

Returns the file's path as a plain String.

    say(File("/home/user/file.txt").to_str)   #=> "/home/user/file.txt"

Aliases: I<to_s>



( run in 1.037 second using v1.01-cache-2.11-cpan-4e7a2411597 )