Skip to content

Instantly share code, notes, and snippets.

@susilolab
Last active November 4, 2019 23:57
Show Gist options
  • Save susilolab/8214785d875974852925bee6a3c86bda to your computer and use it in GitHub Desktop.
Save susilolab/8214785d875974852925bee6a3c86bda to your computer and use it in GitHub Desktop.
Rename nama file yang ada string letmeread
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