2

I have thousands of doted files, folders and subfolders in an external hard disk drive. I want to recover all pictures within these folders. I want to undot them all to easily navigate this pictures.

I've tried renaming the folders, but It doesn't seem possible.

1
  • 1
    "navigate" So with Nautilus? If so: press control-h ;-)
    – Rinzwind
    May 24, 2016 at 14:50

1 Answer 1

2

Name clashes

The first question you need to ask yourself is if there is a chance of name clashes. In other words; if there possibly exist both a hidden version and a non-hidden version of the same directory or file in one and the same directory.

From bottom to top

Assuming that is not the case, this is one of the situations you need to rename from bottom to top, since you cannot rename (move) files inside folders that were just renamed; the script will not find them anymore and break.

Making hidden files visible

Furthermore, while writing this answer, a comment of @Rinzwind just popped up above my head, mentioning pressing Ctrl+H will make all hidden files and folders visible, which is true of course.

If you nevertheless would like to rename the files and folders:

A script to do so

#!/usr/bin/env python3
import os
import sys
import shutil

directory = sys.argv[1]

for root, dirs, files in os.walk(directory, topdown=False):
    for f in files:
        if f.startswith("."):
            shutil.move(os.path.join(root, f), os.path.join(root, f[1:]))
    for dr in dirs:
        if dr.startswith("."):
            shutil.move(os.path.join(root, dr), os.path.join(root, dr[1:]))

How to use

  1. Copy the script into an empty file, save it as rename_dotted.py
  2. Open a terminal and type the command:

    python3 /path/to/rename_dotted.py '<directory>'
    

    where '<directory>' is the directory, needs to be in quotes if it includes one or more spaces.

    As always, please first try on a sample.

2
  • As always a good example at python. +1. Should really get my feet wet in it as well.
    – Videonauth
    May 24, 2016 at 15:10
  • @Videonauth Haha, thanks. The python topdown=False comes handy here :) May 24, 2016 at 15:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .