Dynamic Folder Deletion and contents moved

Posted on 2009-02-12
Last Modified: 2013-11-05

I have a script which is simple, but it needs to have a bit of coding to determine what actions to complete.  Here's the scenario:

Current usage
>>abc.bat  E:\MyFiles TheNewFolder
runSomething.exe %1\%2  //this application foolishly creates a NEW subfolder
//Now exists ---  E:\MyFiles\TheNewFolder\NewSubFolder1828\

The new code needs to copy the files and folders from new *name unknown* subdirectory (named NewSubFolder1828 above) up one level to the [TheNewFolder].

There is only one sub folder.
There are files in the [TheNewFolder] along with the single sub folder.
All the files and folders in the sub folder need to be moved (up one level).
RunSomething.exe basically creates a timestamp folder that is messing everything up!

Question by:ckelker
    LVL 21

    Assisted Solution

    Try this.
    runSomething.exe %1\%2
    for /f "tokens=*" %%a in ('dir /ad /b "%1\%2"') do XCOPY /y /s /c /h "%1\%2\%%a\*.*" "%1\%2\*.*"

    Open in new window

    LVL 1

    Accepted Solution

    Sorry for the delay...

    Code above didn't seem to work but thankfully the required application was tweaked.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
    You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now