简体   繁体   English

从当前文件夹中的所有文件以及子文件夹Windows批处理中的文件中删除前缀

[英]Remove Prefix from all file in current folder as well as files in subfolder windows batch

i am trying to remove prefix from all files in current folder and subfolders i tryed following code which work only for current folder 我正在尝试从当前文件夹和子文件夹中的所有文件中删除前缀,我尝试了以下仅对当前文件夹有效的代码

setlocal enabledelayedexpansion
for %%F in (*) do (
  set "FN=%%F"
  set "FN=!FN:~15!"
  ren "%%F" "!FN!"
)
goto :eof

Please Help me to solve this 请帮我解决这个问题

for /f "delims=" %%a in ('dir /b /a-d /s') do (
    set "fname=%%~nxa"
    set "fpath=%%~dpa"
    setlocal enabledelayedexpansion
    set "nname=!fname:~15!"
    ren "!fpath!!fname!" "!nname!"
    endlocal
)

This is the safe way to preserve exclamation marks. 这是保留感叹号的安全方法。

If you are using windows 7, you could try this: 如果您使用的是Windows 7,则可以尝试以下操作:

forfiles /s /c "cmd /c ren @file @fname"

It took me a bit of time to find, but suddenly I realised that the batch file was not working because it had renamed itself!. 我花了一些时间才找到,但是突然我意识到该批处理文件由于重命名了而无法正常工作。

If this becomes an issue you could try naming the batch file zzzzzzzzz.bat which I think would prevent it from renaming itself first. 如果这成为问题,您可以尝试命名批处理文件zzzzzzzzz.bat ,我认为这将阻止它首先重命名自己。

Mona 莫娜

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用批处理文件向当前文件夹和子文件夹中的所有文件添加前缀 - How to Add prefix to all file in current folder and subfolder using batch file 如何使用此批处理文件将所有* .txt文件从子文件夹复制到批处理文件文件夹? - How to copy all *.txt files from subfolder to batch file folder using this batch-file? 批处理文件以计算文件夹中的所有文件和子文件夹文件,并使用批处理文件以文件夹名称写入输出文件 - batch file to count all files in a folder and subfolder files and write output file in folder name using batch file 在子文件夹而不是当前文件夹中批处理文件 - batch process files in subfolder instead of current folder 从Windows中的所有子文件夹中删除CVS文件夹 - Delete CVS folder from all subfolder in windows 如何使用BATCH文件为文件夹中的所有文件添加和删除后缀 - How to add and remove postfix for all files in folder using BATCH File 命令行(或批处理文件)重命名文件夹中的所有文件 (Windows) - Command Line (or batch file) rename all files in a folder (Windows) Windows批处理:将文件下载到当前文件夹 - windows batch: download file into current folder Windows批处理命令用于从一个文件夹中删除文件 - Windows batch command to delete files from a folder except one file 递归地将文件夹名称附加到其中的文件并将所有文件移动到基本文件夹 Windows 批处理文件 - Recursively append folder name to files in it and moves all files to base folder Windows batch file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM