Batch command to move many folders inside an alfabetic directory structure

久未见 提交于 2019-12-25 04:30:17

问题


I have this content inside a directory

[FOLDERS]
Atomic
Animal
Cat
flash
Zoe

[FILES]
text.txt
audio.rar

I want to reorder moving folders inside an alfabetic directory structure like this (case is irrilevant). I want move only folders no files

A [Atomic, Animal]
C [cat]
f [flash]
Z [zoe]
file1.rar
file2.txt

where A,C,f,Z are parent folders. Folders in bracket are MOVED folders not CONSOLIDATED folders!

Which .bat command can I use?

I want move inside a unique folder called A for all folders that starts with A letter. For folders that starts with F letter I want move them in a single folder called F
Moving is not replacing or merging because I assume that all folders that starts with same letter have different names, I want simply order them by first folder letters.
I don't want consolidate folders in unique folders by letter but only moving in unique folder by first folder letter.

WHAT I WANT


回答1:


@echo off
setlocal enabledelayedexpansion
rem md atomic animal cat flash zoe alfa american banda barca beta brasil cane alfa\subdir
tree
for /d %%i in (*) do (
  set first=%%i
  set first=!first:~0,1!
  md !first! 2>nul
  if not "!first!" == "%%i" move "%%i" "!first!\%%i" 
)
tree

for every directory in the current folder do:
- get the first letter
- create the one letter folder
- if the folder isn't a one letter folder, move it.

use tree to show the result



来源:https://stackoverflow.com/questions/36409228/batch-command-to-move-many-folders-inside-an-alfabetic-directory-structure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!