Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

strip android filenames of illegal characters when copying to windows

Writer Sophia Terry

On my Android phone since years I use an app called 'Fastnote' for notetaking. The notes are automatically saved with a filename that corresponds to the first line of the file.

Such automatic saving is very convenient, but the result is that many of these filenames contain special characters such as " or \ (double quote or slash) which are valid in Android but not in Windows.

Every time I try to backup all my notes (about 1'800 files in 70 folders) onto my PC running Windows 10, those files won't be copied. I can create a zip file which I copy on my PC - so I have a 'backup'. But when I try to unzip this file on the PC, any file with an invalid character in the name won't be copied.

Is there a way to automatically strip all filenames from their invalid characters? This could happen either

  • already on the phone before copying

  • or during the copy operation via USB connection

  • or when unzipping in Windows

EDIT: I need to read the files on my PC, so it's not enough just to have a backup. I actually need to have a FULLY ACCESSIBLE backup on my PC. The only way to do this I see, is to convert the file names into something Windows can handle.

7

1 Answer

The correct way to create a useful backup is just not to use the Android MTP interface for accessing those files.

Instead you should create a backup on-device via adb (requires to activate Development mode and Android Debug Bridge in device settings). Also on the PC side you have to install a minimal version of the Android SDK with ADB.

This has two advantages:

  1. All file-names are preserved - Windows does not have to handle them and therefore can't fail on it.
  2. Creating a backup on-device and later just downloading the combined archive is way more faster: the MTP protocol used by Windows Explorer is very slow, I would expect that the on-device backup creation is 10-20 times faster for such a high number of files.

The two step variant (create TAR archive on-device + download it)

Then create a backup archive on-device:

adb shell tar /sdcard/fastnode_backup.tar /sdcard/<path to fastnote files>

Afterwards you can download the created backup file from your device via

adb pull /sdcard/fastnode_backup.tar

One step variant (create TAR archive and stream it to PC)

Create backup on-device and transfer the created tar archive to the PC - this variant does not require any flash memory on-device):

adb exec-out 'cd /sdcard; tar -cf - <path to fastnote files in sdcard section>/' > fastnode_backup.tar

Or alternatively on devices running Android 8 and newer the fastnode_backup.tar should also appear in the Windows-Explorer view of your device. You can then download this backup file with all file-names preserved inside.

If you still need to access any of those files from within the archive use 7-Zip to extract the files, on your PC or elsewhere. 7-Zip has a built it detection and replacement for invalid file-name characters.

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy