microsoft / PowerToys

Windows system utilities to maximize productivity
MIT License
110.63k stars 6.52k forks source link

Folder collapse (move all files to root) #9269

Open Tundrak opened 3 years ago

Tundrak commented 3 years ago

πŸ“ Provide a description of the new feature

Idea for a new PowerToy: create a new entry in a folder's context menu called: "Dissolve Folder" to release all contents of that folder and every subfolder contained in it outside of it. I'll make an example.

Before running Folder Dissolver:

MainFolder:
   FolderToDissolve:
      Folder1:
         Folder4:
            file1
         file2
     file3
      Folder2:
         file4
      Folder3:
         file5
         file6
      file7
      file8

After running Folder Dissolver:

MainFolder:
   file1
   file2
   file3
   file4
   file5
   file6
   file7
   file8

I know there are ways to make that happen using a .bat file or search, but I feel like an option in the context menu would be much simpler and less clunky to use for me and everyone else that needs it, and a really good quality-of-life addition to the PowerToys suite. I'm also referencing #6388 because it sems to be a container for all new ideas.


If you'd like to see this feature implemented, add a πŸ‘ reaction to this post.

crutkas commented 3 years ago

Would love to better understand the scenario when you'd use this. You're talking about the "what" but not the "why"

Tundrak commented 3 years ago

Actually, I could think of a few use cases for this. Personally, I have created some very large folder structures that I don't understand anymore so I'm not able to find files that I'm sure are there somewhere and I've started making copies to work on them. I can't search them because they're on a slow hard drive and there are thousands of them. Having all of them in front of my eyes would allow me to find alphabetically the ones I need and put them in new (more logically named) folders that I can remember, and also to delete the duplicates I've made that are starting to take up lots of space (maybe that could be done automatically). Also, as another use case my camera stores photos using a strange arbitrary structure with folders and subfolders that don't correspond to anything I can think of, and I find very hard searching for certain pictures. By having them all in one folder, it'd take way less time to look at them and organize them by date. I could even think about a "Start menu declutterer" for all the folders in there that often just contain 1 or 2 shortcuts that you'd rather just see right away without clicking any additional buttons, or a faster way to delete temporary folders made to store things I'd been working on, and now I can merge in the structure.

Jay-o-Way commented 3 years ago

Would love to see something like this. I think it's simple enough so that I could try and script this. Although it obviously needs logic to deal with duplicates.

But, I would use AutoIt and that's not a language that will fit in a project like PowerToys. Also, it can compile to fully stand-alone exe's, but there's something in the compiling process that causes anti-virus software to seriously flag it like a trojan or something. There are so many languages and I just don't know the most common ones good enough to use them.

I think a batch file (if that works) would be the simplest solution/language?

Tundrak commented 3 years ago

Thanks for the interest! I had also thought of trying to write something for it myself (maybe with Python), but it wouldn't be so integrated with the system (like a context menu entry would be). Also I wanted to see what other people thought about putting the utility in a "utility collection" like Powertoys.

There are so many languages and I just don't know the most common ones good enough to use them.

I can relate to that almost too much ;( They should make a "Good first Powertoy" label for these kind of things imo.

Jay-o-Way commented 3 years ago

Okay, so I made a ~script~ exe file that can be triggered via the context menu of a folder. It works, but at this time, there are still a few drawbacks:

If anybody is interested: here is a zip file with the (standalone) exe, script, icon and readme files. If you want to use the script, you can install the software here, then compile. After that, create one or two registry entries (noted in the readme) and try for yourself. FolderCollapse.zip image

P.S. if anybody knows how to translate this into a .bat file or something, let me know? The context menu entry is easy to make.

Jay-o-Way commented 2 years ago

Here I was, being incredibly difficult, when @sredna had an excellent comment with a simple sulution:

REGEDIT4

[HKEY_CURRENT_USER\Software\Classes\Directory\Shell\SillyEmpty\command]
@="cmd /c (for %%A in (\"%1\\*\") do @move /-Y \"%%~fA\" \"%1\\..\\\")&(for /D %%A in (\"%1\\*\") do @move /-Y \"%%~fA\" \"%1\\..\\\")&cd..&rd \"%1\""

[HKEY_CURRENT_USER\Software\Classes\Directory\Shell\SillyRecursiveEmpty\command]
@="cmd /c (for /R \"%1\" %%A in (*) do @move /-Y \"%%~fA\" \"%1\\..\\\")&(for /R \"%1\" %%A in (.) do @rd \"%%~fA\" 2>nul)&cd..&rd \"%1\""

I tested it and it works, only...

image

sredna commented 2 years ago
  • all the files are moved one folder too high - when I click on the folder Collapse I expect all the files inside this folder

I guess I misunderstood. Remove ..\\ from the move commands (although I'm not sure what will happen when you try to move files already in the root). You can also remove the final cd and rd. It was just a proof of concept anyway and should not be taken seriously.

Rather than fighting batch syntax I would recommend that you write this in another language. Even Powershell is able to call SHFileOperation (P/Invoke) giving you the real shell move dialog with rename support for duplicates. It might even be worth looking at Windows Scripting Host, I believe it supports the shell move and the code would work all the way back to Win98.

Jay-o-Way commented 2 years ago

@sredna can't blame you. Looks like you just included the source folder. As I said: "i would expect..."

It was just a proof of concept anyway and should not be taken seriously.

But we do! At least your input is 500% easier than my approach πŸ˜‚ Whatever the exact language/code, it helps a lot towards having a solution for this request. So again: thanks!

sredna commented 2 years ago

This is slightly more serious, it uses the shell copy engine to move the files. Keep in mind that I don't know C# nor PowerShell so I'm sure it has many bugs.

BobbyBoyGaming commented 1 year ago

I can give a new example

Thingiverse Downloads Folder:
   Household Thingamajig Folder:
      Files Folder
         Chassis Parts
            Part A.STL
            Part B.STL
         Body Parts
            Part C.STL
            Part D.STL
         Optional Parts
            Part E.STL
            Part F.STL
      README.txt
      Credits.txt
      OtherTXT.txt

Potential outcome 1: Files folder is eliminated because it is an autogenerated folder by thingiverse that does not itself contain any files only other folders. Then the subfolder names are concatentated into their file names. Filenames can then be further cleaned using the PowerRename Power Toy.

Thingiverse Downloads Folder:
   Household Thingamajig Folder:
      Chassis Parts Part A.STL
      Chassis Parts Part B.STL
      Body Parts Part C.STL
      Body Parts Part D.STL
      Optional Parts Part E.STL
      Optional Parts Part F.STL
      README.txt
      Credits.txt
      OtherTXT.txt

Potential Outcome 2: Toggle off filename concatenation and instead only put the information into a comment ID3Tag, or just delete all information completely.

Thingiverse Downloads Folder:
   Household Thingamajig Folder:
      Part A.STL
      Part B.STL
      Part C.STL
      Part D.STL
      Part E.STL
      Part F.STL
      README.txt
      Credits.txt
      OtherTXT.txt