Last active
November 4, 2019 23:57
-
-
Save susilolab/8214785d875974852925bee6a3c86bda to your computer and use it in GitHub Desktop.
Rename nama file yang ada string letmeread
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule RenameBooks do | |
@book_path "/home/user/Downloads" | |
def get_files do | |
with {:ok, files} <- File.ls(@book_path) do | |
files | |
else | |
{:error, reason} -> | |
reason | |
end | |
end | |
def run do | |
files = | |
Enum.filter(get_files(), fn x -> | |
fullpath = Path.join([@book_path, x]) | |
!File.dir?(fullpath) | |
end) | |
Enum.each(files, fn file -> | |
if String.contains?(file, "Letmeread.net_") do | |
new_name = String.replace(file, "Letmeread.net_", "") | |
old_name = Path.join([@book_path, file]) | |
IO.puts("Renaming '#{file}' to '#{new_name}'..") | |
File.rename!(old_name, Path.join([@book_path, new_name])) | |
end | |
end) | |
end | |
end | |
RenameBooks.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment