<?php
// rename_txt.php
// Renames all *.txt files in the current directory by removing the .txt extension

$dir = __DIR__;

foreach (scandir($dir) as $file) {
    if (is_file($dir . DIRECTORY_SEPARATOR . $file) && str_ends_with($file, '.txt')) {
        $newName = substr($file, 0, -4); // remove ".txt"
        $oldPath = $dir . DIRECTORY_SEPARATOR . $file;
        $newPath = $dir . DIRECTORY_SEPARATOR . $newName;

        // Only rename if target does not already exist
        if (!file_exists($newPath)) {
            rename($oldPath, $newPath);
        }
    }
}