07 Aug 2022, 13:52

Delete Deeply Nested Directories

On Windows.

The problem

Deeply nested directories are sometimes created during the course of software development. Imagine NPM packages, or C# solution with bin\debug directories and dlls named after project name. It quickly adds up. Issue is exacerbated with tendency of (some) development tools to suggest user dir as a home for new stuff. As a result we get a file path like C:\Users\user.name\source\project\MyAwesomeCompany.MyAwesomeProduct\MyAwesomeCompany.MyAwesomeProduct.Repository.Interface\bin\debug\MyAwesomeCompany.MyAwesomeProduct.Repository.Interface.dll

With even more creative names hitting the maximum path length of 260 characters is within reach :)

Deleting such path can prove difficult as doing it from Windows Explorer fails. Sometimes, a directory near the root can be renamed to one character which then helps with the delete. Sometimes, that does not work either.

Robocopy

One approach that consistently works and does not depend on third party utilities is using robocopy:

  1. create an empty directory, e.g. c:\temp
  2. open command prompt
  3. copy and paste the following command, replacing the example directory with the one you want to delete:
robocopy c:\temp C:\Users\user.name\source\project\MyAwesomeCompany.MyAwesomeProduct /mir

Essentially, it tells robocopy to mirror the source directory onto the destination. Since the source is empty, it will delete everything in the destination. And it will do that quickly.

Bonus tip - if there is space somewhere in problem directory path, double quotes can be used:

robocopy c:\temp "C:\Users\user with a space\source\project\MyAwesomeCompany.My Awesome Product" /mir

07 Oct 2018, 20:21

Poor Man's Profiler

If you’re having issues regarding performance, i.e. application is slow, a quick and dirty solution can be to

  1. trigger slow code (from UI, etc.) and then
  2. press pause button in the IDE Image of pause button in Android studio

Chances are that two out of three times call stack will be stuck in the expensive method call.

Image of call stack

Then, you can simply have a glance at what each method does:

fun innocentMethod1() {
    innocentMethod2()
}

fun innocentMethod2() {
    innocentLookingMethod()
}

Nothing suspicious here.

But, move on and you might see something like:

fun innocentLookingMethod() {
    for (i in 1..1000000) {
        innocentMethod3(i)
    }
}

which should be a good enough starting point for further work.

Credits

Credits for the idea, however it may seem simple, are due to a blog or forum post somewhere, sometime.