Batch command to move many folders inside an alfabetic directory structure

时间:2016-04-04 17:35:41

标签: batch-file batch-processing directory

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 个答案:

答案 0 :(得分:0)

@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

对于当前文件夹中的每个目录执行:
- 获取第一个字母
- 创建单个字母文件夹
- 如果文件夹不是单个字母文件夹,则移动它。

使用tree显示结果