2

So, I have a directory structure like this:

parent/
└── sub1
|    └── sub1.1
|    |    └── source
|    |        └── something1
|    |        └── something2
|    |   
|    └── sub1.2
|         └── source
|             └── something3
|             └── something4
└── sub2
    └── sub2.1
    |    └── source
    |        └── something5
    |        └── something6
    |   
    └── sub2.2
    |     └── source
    |         └── something7
    |         └── something8
    |   
    └── sub2.3
          └── source
              └── something9
              └── something10

I want to move all files (with different filename) from all directories named source to its relative upper/parent directory. So, the result should be something like this:

parent/
└── sub1
|    └── sub1.1
|    |        └── something1
|    |        └── something2
|    |   
|    └── sub1.2
|             └── something3
|             └── something4
└── sub2
    └── sub2.1
    |        └── something5
    |        └── something6
    |   
    └── sub2.2
    |         └── something7
    |         └── something8
    |   
    └── sub2.3
             └── something9
             └── something10

There is a linux example but i am after a batch version.

EDIT: Thanks, that should work. I originally had the below but it will only do one subfolder deep.

@echo off
for /D %%I in ("%~dp0*") do (
    if exist "%%I\source\*" (
        move /Y "%%I\source\*" "%%I\" 2>nul
        rd "%%I\source" 2>nul
    )
)
Nate
  • 21

1 Answers1

0

Here is a small C# program.

using System;
using System.IO;

namespace Move { class Program { static void Main(string[] args) { Console.Write("Folder: "); string path = Console.ReadLine();

    foreach (var folders in Directory.GetDirectories(path)) {
        Console.WriteLine(folders);

        foreach (var subs in Directory.GetDirectories(folders)) {
            Console.WriteLine($"\t{subs}");

            foreach (var source in Directory.GetDirectories(subs)) {
                Console.WriteLine($"\t\t{source}");

                foreach (var item in Directory.GetFiles(source)) {
                    Console.WriteLine($"\t\t\t{item}");

                    string filename = Path.GetFileName(item);

                    string newPath = $@"{subs}\{filename}";
                    File.Move(item, newPath);
                }

                    Directory.Delete(source);
                }
            }

        }


        Console.ReadLine();
    }
}

}

Klorissz
  • 381