Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Files with arabic names

by Anonymous Monk
on Jul 13, 2017 at 18:23 UTC ( #1195063=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello, Can someone please suggest how to delete filename contains other than english language. Like the below

Example file names:-

jdid rai dz cheb mourad 2017- No No No Madamti new album شاب مراد كالعادة يصرع

✪ Lotfi Double Kanon✪ 2017 جديد ⁄ أنا

Please note that , I dont have inode number details for these files.

Thanks

Replies are listed 'Best First'.
Re: Files with arabic names
by 1nickt (Canon) on Jul 13, 2017 at 18:44 UTC

    Same way as any other file, with unlink. Your computer doesn't care what language the filename is in.

    $ perl -Mstrict -MPath::Tiny -wE '
    my $filename = "شاب مراد كالعادة يصرع";
    path( $filename )->spew("Hello, world");
    say qx{cat "$filename"};
    unlink $filename;
    say qx{ls "$filename"};
    '
    Hello, world
    ls: شاب مراد كالعادة يصرع: No such file or directory
    

    Perhaps you meant something else? Maybe you need to learn about character encoding? See for example perlunitut, or this node.


    The way forward always starts with a minimal test.

      This is only true if the character encoding used is the same between Perl and the other process(es) showing the files.

      On Unixish systems, filenames are opaque blobs of octets and all interpretation of them as UTF-8 octets is solely by convention.

      On Windows systems, filenames are encoded as wide characters (UTF-16) and you have to use the Wide APIs to access/delete them. If your filenames are encoded as UTF-8, you have to change their encoding to UTF-16 when talking to the Windows API.

      Win32::Unicode helps there.

        Well, the OP was rather vague about where the filenames were, and his real issue is character encoding, not deleting files, don't you think? That's what I was attempting to point out.


        The way forward always starts with a minimal test.
        A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Files with arabic names
by Anonymous Monk on Jul 13, 2017 at 18:35 UTC

      I'm looking for script in UNIX based systems. I have list of files in file. I'm able to process and delete files in English ( ASCII ) language through unlink function , but unable to delete these in other language.

      If no such solution then I can try from windows system ( mount fs on windows ).

      Any lead appreciated.
        but unable to delete these in other language

        Please see How do I post a question effectively? and show us an SSCCE with which we can reproduce the problem on our end. I'd have to guess that maybe it has something to do with the encoding of the file containing the list of files, see e.g. encguess for a way to find out how it's encoded. The following works for me, my terminal is entirely UTF-8. Note how I specify the file's encoding in the open.

        $ touch 'jdid rai dz cheb mourad 2017- No No No Madamti new album شاب مراد كالعادة يصرع'
        $ touch '✪ Lotfi Double Kanon✪ 2017 جديد ⁄ أنا'
        $ ls jdid* *Lotfi* >list.txt
        $ cat list.txt 
        jdid rai dz cheb mourad 2017- No No No Madamti new album شاب مراد كالعادة يصرع
        ✪ Lotfi Double Kanon✪ 2017 جديد ⁄ أنا
        $ encguess list.txt
        list.txt	UTF-8
        $ perl -wMstrict
        open my $fh, '<:encoding(UTF-8)', 'list.txt' or die $!;
        chomp( my @files = <$fh> );
        close $fh;
        my $count = unlink(@files);
        print "Deleted $count files\n";
        __END__
        Deleted 2 files
        $ ls
        list.txt
        $ 
        

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1195063]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2022-05-23 05:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (81 votes). Check out past polls.

    Notices?