#1 11 Nov 2018 12:30

wquatan
Member
Registered: 19 Jun 2012
Posts: 15

Rename Subdir

I have a Directory structure which looks like this :
Dir\SubDir1\SubDir2\SubDir3\Files

I would like to rename it as such:
Dir\SubDir1SubDir2\SubDir3\Files

So actually combining the names of SubDir1 and SubDir2

Is there a way to do that in cmd ?

Last edited by wquatan (11 Nov 2018 12:30)

Offline

#2 12 Nov 2018 13:20

Pyprohly
Member
Registered: 26 Nov 2014
Posts: 37

Re: Rename Subdir

Yes.

mkdir "Dir\SubDir1SubDir2"
move "Dir\SubDir1\SubDir2\SubDir3" "Dir\SubDir1SubDir2"
rmdir "Dir\SubDir1\SubDir2"
rmdir "Dir\SubDir1"

Offline

#3 12 Nov 2018 14:58

wquatan
Member
Registered: 19 Jun 2012
Posts: 15

Re: Rename Subdir

Hi,

That's the manual way  smile which I knew of course.

My question was for an automatic way by getting Subdir1 and Subdir2 and creating Subdir1Subdir2 dynamically (and this for all existing Subdir1 / Subdir2 )

Offline

#4 12 Nov 2018 15:36

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,052

Re: Rename Subdir

In fairness, you didn't actually express the full nature of your request -- the question as it was asked was answered.  But it turns out that you asked the wrong question wink

Here's something to do what I think you're actually asking:

@echo off
for /d %%a in (Dir\*.*) do (
  for /d %%b in (%%a\*.*) do (
    move "%%~b" "%%~a%%~nxb"
    rmdir "%%~a"
  )
)

Last edited by bluesxman (13 Nov 2018 10:15)


cmd | *sh | Ruby | Chef | Puppet | PowerShell | AutoIT3

Offline

Board footer

Powered by FluxBB