-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdirmap.pl
More file actions
156 lines (136 loc) · 7.21 KB
/
dirmap.pl
File metadata and controls
156 lines (136 loc) · 7.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/perl -w
#
# File/Dir Mapping script - v0.1
# ------------------------------
#
# (unnecessarily verbose) Backstory:
# Over the years I've accumulated a lot of really badly organised folders on my home server. I've got backed up PCs
# from my university days, random USB drive dumps and various (heavily duplicated) photo folders. All of these were of
# course going to be processed on a rainy day when I have nothing else to do (you know, those days that don't exist).
#
# So it got out of hand. I lived with it. But sometimes I need to find a file and I can't for the life of me remember
# where I saw that file, or which copy of 'My Documents' from which defunct laptop backup it lives in. I needed
# something that I could process visually. A map, to make some sense of this haystack.
#
# This is the solution, sort of. It's still a mess, but at least now I can quickly visualise what's in the monster
# filedump. It saves time.
#
# Aaaanyway, here's one of my motorbikes. Because life always needs more motorbike.
#
# I::
# ~+
# D:M:
#
# $$7M8 78:
# ~M8NMD8DO DMNO
# : : 8IO:MMMMZM$~
# 7~ ~ ~::::::::+$ MNZMMMZM$
# +: $Z$$I$Z7$$$ ~ : : :::7$~+7+ MM+ MMMNNN
# I ?ND888OOOZ$$ = =~78MMN ::~+OONMMNMMMMN
# $?ZM$=I =DMMNNDD8Z$7 I :=~+D=+M8$D?: :$ZMMM8MD8M?
# INM8M: I :IMNNND8ZZZZZ$$Z$$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DDNNMM8 8DN8MDNNDD88DDZ
# :8NNNNMMMO++++=+==+++==+===========~~::: :::::::MNNDNNDNM
#
#
# Usage:
# Put it anywhere. Specify the $dir value as the folder that you want to map. Run the script. The script creates a
# mind map file at the base of that directory.
#
# Open the file with Freemind (http://goo.gl/54miZt).
# ???.
# Profit. (sorry)
#
# --------------------------------------------------------------------------------------------------------------------
#
# Stuff what I ripped off to make this (because I am NOT a Perl coder):
# - I used this Perl Monks script initially: http://www.perlmonks.org/?node_id=136482
# - Then pulled the file output logic from here: http://perlmaven.com/writing-to-files-with-perl
# - I made a Freemind .mm file and opened it up in a text editor. I copied the node structure from that.
#
# --------------------------------------------------------------------------------------------------------------------
#
# Change Log
# ----------
#
# Fri 19 Dec 2014
# Added dir as param.
#
# Thu 18 Dec 2014
# Written on a coffee break by Matt Fenlon (https://github.com/noln)
#
#
#
# Note: Adheres to no commenting convention known to man(/woman, keep it contemporary)kind. Becauyse life's too short.
# Look, it's a freebie. What do you want? Just run the damn script.
#
# Roadmap
# -------
# 1. Add file extension filter.
# 2. Enable crawling of remote directories fia SFTP.
#
use feature qw(say); # Added so we can use 'say' to output text on a new line.
use File::Basename; # Needed to split up the returned filename into dir and filename etc.
say "Wootini";
my $dir;
$num_args = $#ARGV + 1;
if ($num_args != 1) {
$dir = "/Users/matt/Development/Media/Android"; # This is where the file map gets put.
say "Using default path: " . $dir;
} else {
$dir = $ARGV[0];
say "Using path: " . $dir;
}
my $filename = 'filemap.mm';
#my $dir = "/Users/matt/Development"; # This is where the file map gets put.
# my $dir = "/Users/matt/Development/Media/Android"; # This is where the file map gets put.
open(my $fh, '>', $dir . '/' . $filename) or die "Could not open file '$filename' $!";
# This is horrific hackery, and none of the attributes are generated as they should be, but it loads. So I'm happy.
print $fh "<map version=\"0.9.0\">
<!-- To view this file, download free mind mapping software FreeMind from http://freemind.sourceforge.net -->
<node CREATED=\"1\" ID=\"ID_1\" MODIFIED=\"1418909179964\" TEXT=\"" . $dir . "\">\n";
process_files ($dir);
print $fh ("</node></map>");
close $fh;
print "done\n";
# Accepts one argument: the full path to a directory.
# Returns: nothing.
sub process_files {
my $path = shift;
# Open the directory.
opendir (DIR, $path)
or die "Unable to open $path: $!";
my @files = grep { !/^\.{1,2}$/ } readdir (DIR);
closedir (DIR);
@files = map { $path . '/' . $_ } @files;
for (@files) {
# If the file is a directory
if (-d $_) {
my($file, $dir, $ext) = fileparse($_);
print $fh ("<node CREATED=\"2\" ID=\"ID_2\" MODIFIED=\"1418909183375\" TEXT=\"" . $dir . "\">");
process_files ($_);
print $fh ("</node>\n");
# If it's just a file
} else {
# This splits the file (which includes the full path at this point) into filename, dir and file extension.
my($file, $dir, $ext) = fileparse($_);
print $fh ("<node CREATED=\"2\" ID=\"ID_2\" MODIFIED=\"1418909183375\" TEXT=\"" . $file . "\"/>\n");
}
}
}