Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Folder collapse (move all files to root) #9269

Open
Tundrak opened this issue Jan 25, 2021 · 12 comments
Open

Folder collapse (move all files to root) #9269

Tundrak opened this issue Jan 25, 2021 · 12 comments
Assignees
Labels
Idea-New PowerToy Suggestion for a PowerToy Status-In progress This issue or work-item is under development

Comments

@Tundrak
Copy link

Tundrak commented Jan 25, 2021

📝 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.

@Tundrak Tundrak added the Needs-Triage For issues raised to be triaged and prioritized by internal Microsoft teams label Jan 25, 2021
@Aaron-Junker Aaron-Junker added the Idea-New PowerToy Suggestion for a PowerToy label Jan 25, 2021
@crutkas crutkas changed the title [New PowerToy] Folder Dissolver [New PowerToy] Folder collapse (move all files to root) Jan 26, 2021
@crutkas
Copy link
Member

crutkas commented Jan 26, 2021

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

@crutkas crutkas added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Triage For issues raised to be triaged and prioritized by internal Microsoft teams labels Jan 26, 2021
@Tundrak
Copy link
Author

Tundrak commented Jan 27, 2021

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.

@ghost ghost added Needs-Triage For issues raised to be triaged and prioritized by internal Microsoft teams Needs-Team-Response An issue author responded so the team needs to follow up and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Jan 27, 2021
@crutkas crutkas removed Needs-Team-Response An issue author responded so the team needs to follow up Needs-Triage For issues raised to be triaged and prioritized by internal Microsoft teams labels Jan 28, 2021
@crutkas crutkas added this to the Suggested Ideas milestone Jan 28, 2021
@Jay-o-Way
Copy link
Collaborator

Jay-o-Way commented Jul 14, 2021

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
Copy link
Author

Tundrak commented Jul 15, 2021

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
Copy link
Collaborator

Jay-o-Way commented Aug 17, 2021

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:

  • I have compiled it to a standalone .exe file - which i have included in the zip below - but unfortunately, this might be an issue: https://www.autoitscript.com/wiki/AutoIt_and_Malware. The exe file can be exluded after detection by anti-malware, but #cumbersome...
  • The logic is far from ideal. I have tried to list sub-folders and then DirMove all of them to the root folder, but unfortunately [quote] If the destination already exists and the overwrite flag is specified then the source directory will be moved inside the destination. [/quote] In other words, when it gets to the first-level folders, "source = destination" and it sucks fails. Therefore I needed to approach it via a FileMove function followed by deleting all the empty folders. Maybe a hybrid solution in the future?
  • When there are no sub-folders to begin with, it fails on the _FileListToArrayRec function. Error message is hidden (or ignored) and the result is obviously the same (no sub-folders) but something feels fishy.
  • The overwrite flag is set to 1, so be aware that all duplicates will be merged without warning!

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.

@crutkas crutkas changed the title [New PowerToy] Folder collapse (move all files to root) Folder collapse (move all files to root) Dec 20, 2021
@Jay-o-Way
Copy link
Collaborator

Jay-o-Way commented Jan 31, 2022

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...

  • all the files are moved one folder too high - when I click on the folder Collapse I expect all the files inside this folder
  • have to find a way to deal with duplicate filenames and files that have the readonly flag:

image

@sredna
Copy link
Contributor

sredna commented Jan 31, 2022

  • 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
Copy link
Collaborator

@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
Copy link
Contributor

sredna commented Jan 31, 2022

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
Copy link

BobbyBoyGaming commented May 22, 2023

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

@Aaron-Junker Aaron-Junker self-assigned this Feb 1, 2024
@Aaron-Junker Aaron-Junker added the Status-In progress This issue or work-item is under development label Feb 29, 2024
@Aaron-Junker Aaron-Junker mentioned this issue Feb 29, 2024
14 tasks
@Aaron-Junker Aaron-Junker moved this to ⚒️In progress in 1. Current/Upcoming Releases Oct 9, 2024
@Aaron-Junker Aaron-Junker moved this from ⚒️In progress to 📑In Review in 1. Current/Upcoming Releases Oct 9, 2024
@Aaron-Junker Aaron-Junker moved this from 📑In Review to ⚒️In progress in 1. Current/Upcoming Releases Oct 9, 2024
@Aaron-Junker Aaron-Junker moved this from ⚒️In progress to 📑In Review in 1. Current/Upcoming Releases Oct 9, 2024
@daverayment
Copy link
Contributor

I think this is a great idea, and I've had the need to flatten a deeply-nested directory structure a few times in the past.

However, I wonder if an alternative is possible by creating a separate non-destructive 'view' of the files rather than the process of moving everything into the parent folder and then removing all the child folders. I tried developing such a tool a while ago with a virtual filesystem, but never finished it. I also have a PowerShell script which creates a folder of symlinks representing the nested files, which I'm happy to share if anyone is interested, but I imagine a pure C# implementation would fit better with PowerToys.

@Jay-o-Way
Copy link
Collaborator

FYI - the Files app now has this ability as an experimental function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Idea-New PowerToy Suggestion for a PowerToy Status-In progress This issue or work-item is under development
Projects
Status: 📑In Review
Development

No branches or pull requests

7 participants