0

consider following folder structure:

root
  Folder1
    file1.txt
    file2.dat
  Folder2
    file3.doc
    file4.pdf
  rename.bat

I want to rename the files (using rename.bat) according to the name of the respective subdirectories, copy them to the root directory and delete the subfolders so that I get

root
  Folder1.txt
  Folder1.dat
  Folder2.doc
  Folder2.pdf
  rename.bat

Actually I know this is possible (and actually with very few lines of code) since I already found the code somewhere some time ago. Sadly I lost my scipt and am not able to find the code again now.

Regards, Eduard

4

3 回答 3

0

这使用 Mona 的代码,但处理长文件名。在一些示例文件夹上进行测试。

称它为 renfolder.bat 或其他名称,因为 rename.bat 使用内部命令的名称。

@echo off
for /d %%a in (*) do (
cd "%%a"
for %%b in (*) do (
echo copying "%%a%%~xb"
copy "%%b" "\%%a%%~xb" >nul
)
cd..
rd "%%a"
)
pause
于 2013-06-24T03:35:44.533 回答
0

在这里,我把它变成了我自己。我创造了一个与你类似的情况,对我来说效果很好。但是,您必须指定将所有文件复制到的位置。

for /d %%a in (*) do (
cd %%a
for /r %%b in (*) do (
copy %%b C:\ [root] \%%a%%~xb
)
cd..
)
pause

希望这会有所帮助。

你的莫娜。

于 2013-06-24T03:11:33.397 回答
0

感谢您的回答!

我改进了您的代码以按预期工作,因此它现在完全符合我的需求:

@echo off
for /d %%a in (*) do (
  cd "%%a"
  for %%b in (*) do (
    echo moving "%%a\%%b" to "%%a%%~xb"
    move "%%b" "..\%%a%%~xb"
  )
  cd ..
  rd "%%a"
)
于 2013-07-21T14:11:21.910 回答