Comment detail

指定されたフォルダ以下のゴミ掃除 (Nested Flatten)
erl -noshell -eval 'delbackup:delbackup("."), halt().'
のように実行します.
 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
-module(delbackup).
-export([delbackup/1]).

delbackup(RootPath) ->
        check_dir(RootPath).

check_dir(Path) ->
        case file:list_dir(Path) of
                {ok, FileList} ->
                        check_file(Path, FileList);
                {error, Reason} ->
                        io:format("Error. ~s (~p)~n", [Path, Reason])
        end.

check_file(Path, [File|RestFile]) ->
        FilePath = Path ++ "/" ++ File,
        io:format("~s~n", [FilePath]),
        IsDir = filelib:is_dir(FilePath),
        IsFile = filelib:is_file(FilePath),
        case {IsDir, IsFile} of
                {true, _} ->
                        check_dir(FilePath);
                {_, true} ->
                        check_backup(FilePath);
                _Other ->
                        ok
        end,
        check_file(Path, RestFile);
check_file(_Path, []) ->
        ok.

check_backup(FilePath) ->
        case regexp:match(FilePath, "~$") of
                {match, _, _} ->
                        file:delete(FilePath),
                        io:format("delete ~s~n", [FilePath]);
                _Else ->
                        ok
        end.

Index

Feed

Other

Link

Pathtraq

loading...