无需下载其他软件即可重命名多个文件

无需下载其他软件即可重命名多个文件

当我重置笔记本电脑时,备份和恢复出了问题。现在我的所有文件都像这样:备份错误后的文件名

我尝试通过 Windows 恢复将驱动器重新添加为恢复选项(希望如果我能够进行恢复,软件会自动将所有这些文件带回我的笔记本电脑,而不需要备份日期信息),但 Windows 恢复工具拒绝识别已保存到此驱动器上的 FileHistory。

现在我只想将这些文件剪切粘贴(移动)到笔记本电脑上,并想办法删除备份日期信息。

在意识到一定有办法自动执行这项繁琐的任务之前,我已经手动对一些文件进行了这样的操作。

有没有办法重命名所有这些文件,以便删除备份日期信息没有需要下载任何外部软件吗?

我读完了我如何批量重命名文件?但我仍然不知道该怎么做。

优先:

  • 当整个文件夹从外部驱动器移动到笔记本电脑时,会发生重命名
  • 未对文件详细信息(例如“修改日期”)进行任何更改

编辑:

示例:备份文件位于我的外部驱动器上的以下位置:
D:\FileHistory\myuser\LAPTOP-78RBSL7E\Data\C\Users\myuser\Desktop\Education\High School\G12\Politics

它应该复制到我的笔记本电脑上的这个位置:
C:\Users\myuser\Desktop\Education\High School\G12\Politics

Culminating Essay (2021_05_02 18_14_18 UTC)文件名应从Culminating Essay

此名称更改也应适用于 zip 文件

答案1

您可以创建一个批处理文件来完成该任务。将下面的代码复制到记事本,然后以您想要的名称保存,但扩展名为 *.bat。

根据您的需要更改此部分,然后单击批处理文件设置源=设置命运=

@echo off
:: here you infrorm the script where the source and destiny are:
set Source=D:\FileHistory\myuser\LAPTOP-78RBSL7E\Data\C\Users\myuser\Desktop\Education\High School\G12\Politics
set Destiny=C:\Users\myuser\Desktop\Education\High School\G12\Politics

:: This gets the full path of the source:
for /f "delims=" %%a in ("%Source%") do set Source=%%~dpnxa
:: This creates the destiny in case it doesn't exist already:
IF not exist "%Destiny%\" md "%Destiny%"

:: This sends the full path of each source file to the rename funcion
For /f "Delims=" %%a in ('dir /b /s /a-d "%Source%\*"') do call :Rename "%%~a"

exit

:: Here the renaming is done:
:Rename
set "PartName=%~1"
call set "PartName=%%PartName:%Source%=%%"
for /f "tokens=1,3 delims=()" %%a in ("%PartName%") do set "PartName=%%~a"
if "%PartName:~-1%"==" " set "PartName=%PartName:~0,-1%"
IF /i not exist "%Destiny%%PartName%%~x1" echo F |xcopy /q /k "%~1" "%Destiny%%PartName%%~x1"
goto :EOF

在此处输入图片描述

答案2

不是最有效的电源外壳代码,但这是我脑海中最直接的代码。

$BackupFileRoot = 'D:\FileHistory\myuser\LAPTOP-78RBSL7E\Data\C\Users\myuser'
$RestoreToRoot  = 'C:\Users\myuser'

### Recreate Directory Structure

(Get-ChildItem $BackupFileRoot -Directory -Recurse).FullName | ForEach{
    $RestorePath = $_.Replace( $BackupFileRoot , $RestoreToRoot  ) 
    If ( !( Test-Path $RestorePath ) )
    {
        md $RestorePath -Force | out-null
    }
}

### Restore Files

$RegExFind = ' \([\w ]+UTC\)'
Get-ChildItem $BackupFileRoot -File -Recurse -Force | ForEach{
    $RestorePath = $_.FullName.Replace( $BackupFileRoot , $RestoreToRoot  ) -replace ( $RegExFind , '' )
    If ( !( Test-Path -LiteralPath $RestorePath ) )
    {
        Copy-Item -LiteralPath $_.FullName $RestorePath
    }
}

相关内容