-
Notifications
You must be signed in to change notification settings - Fork 33
/
notepadfree_to_txt.pl
executable file
·47 lines (36 loc) · 1.28 KB
/
notepadfree_to_txt.pl
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
#!/usr/bin/perl
# Convert Android Notepad Free backup notes to text files.
use utf8;
use 5.014;
use autodie;
use warnings;
use JSON qw(from_json);
use File::Slurper qw(read_text write_text);
use File::Spec::Functions qw(catfile updir);
use File::Compare qw();
my $output_dir = 'Text files';
my $meta_json = from_json(read_text('notes_meta_data.json'));
if (not -d $output_dir) {
mkdir($output_dir);
}
OUTER: foreach my $note (@{$meta_json->{notes}}) {
my $title = $note->{title};
my $file = $note->{file};
my $lastEditDate = $note->{lastEditDate};
$title =~ s{/}{÷}g; # replace '/' with '÷'
my $input_file = catfile(updir, $file);
my $content = read_text($input_file);
my $output_file = catfile($output_dir, $title . '.txt');
for (my $k = 1 ; (-f $output_file) ; ++$k) {
if (File::Compare::compare($input_file, $output_file) == 0) {
say "File `$output_file` already exists... Skipping...";
next OUTER; # files are equal
}
else {
$output_file = catfile($output_dir, $title . '_' . $k . '.txt');
}
}
say "Creating: `$output_file`...";
write_text($output_file, $content);
utime($lastEditDate, $lastEditDate, $output_file);
}