不清楚你的实际文件/情况,仅以问题中的样例/说明为据;以下代码复制粘贴到记事本,另存为xx.bat,编码选ANSI,跟要处理的文件夹放一起运行
<# :
cls
@echo off
rem 将一个指定目录里的多个子文件夹内的所有文件的名称开头插入该文件所有上级文件夹/目录的名称
mode con lines=3000
set #=Any question&set @=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%@% %z%
cd /d "%~dp0"
powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::Default)))"
echo;%#% +%$%%$%/%@% %z%
pause
exit
#>
$path="D:\xxx\指定文件夹";
if(-not (test-path -liter $path)){Write-host ('"'+$path+'" not found');exit;};
$s="-";$files=@(dir -liter $path -recurse|?{$_ -is [System.IO.FileInfo]});
for($i=0;$i -lt $files.length;$i++){
$ofd=$files[$i].Directory.FullName.substring($path.trimend('\').length);
if($ofd -ne ''){
$nfd=$ofd.trim('\').replace('\',$s);
$f=$false;$newname=$nfd+$s+$files[$i].Name;
if($files[$i].BaseName.length -lt $nfd.length){
$f=$true;
}else{
if($files[$i].BaseName.substring(0,$nfd.length) -ne $nfd){
$f=$true;
};
};
if($f){write-host ($files[$i].FullName+' --> '+$newname);};
};
}
追问提示有病毒呢
追答那就别用啰,还想我咋样