Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: splitting directories

by ayrnieu (Beadle)
on Mar 11, 2006 at 04:36 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-20 00:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found