@ECHO OFF&SETLOCAL ENABLEDELAYEDEXPANSION
FOR /f "delims=" %%i in ('dir /a-d 升举/s /b %~dp0\*.*') do (
SET fp=%%~dpi
SET 歼笑中fp=!fp:%~dp0=!-%%~nxi
SET fp=!fp:\=!
XCOPY "%%i" "e:\新建文件夹\!fp!" /c /h /d
)
PAUSE
注意:复制粘贴时请把记事本的自动换行选项关掉.以防止氏山粘贴时出现格式问题.
@echo off&setlocal 穗雹肢enabledelayedexpansion
for /f "delims=" %%a 猜世in ('肆梁dir /b/s/a-d') do (
set "str=%%~pa"
for /f "delims=" %%b in ("!str:\=.!") do (
set "str=%%~xb"
copy "%%a" "e:\新建文件夹\!str:~1!-%%~nxa"
)
)
1. 如果仅将文件的上级文件夹作为新文件名的一部分毕野,代码如下:
@echo off&setlocal enabledelayedexpansion
for /r "%~dp0" %%i in (*.*) do (
set "str=%%~dpi"
set "str=!str:~0,-1!"
for %%j in ("!str!") do copy "%%i" "e:\新建文手槐喊件夹\%%~nxj-%%~nxi">nul
)
2. 如果需要要将各级子文件夹作为新文件名的一部分,代码如下:
@echo off&setlocal enabledelayedexpansion
for /r "%~dp0" %%i in (*.*) do (
set "str=%%~i"
set "str=!str:%~dp0=!"明脊
copy "%%i" "e:\新建文件夹\!str:\=-!" >nul
)
@echo off
xcopy . 指定位置 /e