- 1 year ago
batch convert base64 encoded file names Windows
To batch convert base64-encoded file names in Windows using a batch script, you can utilize the certutil
command-line tool, which is available in Windows by default. Here's an example of how you can achieve this:
Open a text editor and create a new batch file (e.g.,
convert_filenames.bat
).Inside the batch file, write the following code:
batch@echo off
setlocal enabledelayedexpansion
set "source_dir=C:\path\to\source\directory"
for /f "delims=" %%F in ('dir /b /a-d "%source_dir%\*.txt"') do (
set "encoded_name=%%~nF"
set "decoded_name="
for /f %%A in ('echo !encoded_name! ^| certutil -decodeHex') do set "decoded_name=%%A"
ren "%source_dir%\%%F" "!decoded_name!"
)
echo Batch file name conversion completed.
Modify the
source_dir
variable to specify the directory containing the files with base64-encoded names that you want to convert. ReplaceC:\path\to\source\directory
with the actual path to your source directory.Save the batch file.
Open a command prompt and navigate to the directory where the batch file is located.
Run the batch file by typing its name and pressing Enter:
convert_filenames.bat
The batch script will iterate through all the files with the .txt
extension in the specified source directory. For each file, it will extract the base64-encoded name, decode it using certutil
, and rename the file with the decoded name. The original files will be replaced with the renamed files.
Make sure to test the script on a backup or test data before running it on your actual files to ensure it works as expected.