Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: splitting directories

by ayrnieu (Beadle)
on Mar 11, 2006 at 04:36 UTC ( #535873=note: print w/replies, xml ) Need Help??


in reply to splitting directories

#! /usr/bin/env perl use strict; use warnings; die "usage: $0 <dir>" unless @ARGV == 1; chdir $ARGV[0] or die "chdir failed: $!"; my @files = grep { not /^(?:\.|\.\.)$/ } readdir '.'; my $i = 0; for (my $i = 0; @files; $i++) { mkdir $i or die "mkdir $i failed: $!"; for (splice @files, 0, 1000) { rename $_, "$i/$_" or die "rename $_ $i/$_ failed: $!"; } }

Adjust for win32 as needed.

For fun, perl6:

#! /usr/bin/env perl use v6; use fatal; # or is this default? die "usage: $*PROGRAM_NAME <dir>" unless @*ARGS == 1; chdir @*ARGS[0]; my @files = grep { $_ ne '.'&'..' } readdir '.'; loop (my $i = 0; @files; $i++) { mkdir $i; rename $_, "$i/$_ for splice @files, 0, 1000; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2022-01-24 14:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (64 votes). Check out past polls.

    Notices?