Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 06, 2016, 02:18:54 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: IDEA: Quickly remove redundant recursive folders  (Read 3665 times)

justW3

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 11
  • What you think I said is probably not what I meant
    • View Profile
    • Donate to Member
IDEA: Quickly remove redundant recursive folders
« on: November 29, 2011, 04:12:32 AM »
I wonder if anyone can help or advise.  I am looking for a simple way to easily remove recursive similarly-named folders.

So, rather than have something like "C:\this_is_a_folder\this is a folder\data contents" I'm looking for an easier way of ending up with "C:\this is a folder\data contents" without having to do lots of manual moving of files in order to delete the redundant "\this_is_a_folder" folder. 

I come across the problem of too many nesting similarly-named folders a lot when unpacking RAR archives. On occasion, if the archive has been repacked more than once, I have even found some unpacked archives ending up as "C:\this_is_a_folder\this is a folder\this is a folder\data contents", or an even longer chain of similarly named folders.  Most exasperating.  :huh:

Thanks.  :)

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,283
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: IDEA: Quickly remove redundant recursive folders
« Reply #1 on: November 29, 2011, 06:23:13 PM »
I don't really want to muck about deleting folders on your system. But I have a script that should detect a chain with consecutive dupes if you select a folder below the dupes and press a hotkey.

It feeds the folders to a file manager. I have FreeCommander hard wired but you can change it to any file manager that will accept 2 folders on the command line.

As example, if you have c:\mydocs\mydocs\mydocs\docs

select "docs" in explorer and hit Shift-F8

FreeCommander should come up with c:\mydocs on one side and c:\mydocs\mydocs on the other.  You would highlight the "docs" folder under c:\mydocs\mydocs and press F6 move.

If the hotkey routine does not detect a dupe chain it gives a sour "ding".
If it does it chimes so you now the file manager is coming up.

It's AutoIt3

#include <Sound.au3>

Global $terminalFolder = ""
Global $rootFolder = ""
Global $dirs[1]
Global $folders[1]
Global $x = 0, $y = 0
If Not HotKeySet("+{F8}", "ClipFolders") Then
MsgBox(0x1010, "DupeFolder", "Hot Key Set Failure: Please Choose a different Hotkey")
Exit
EndIf

While 1
Sleep(250)
WEnd

Func ClipFolders()
Send("^c")
Sleep(100)
$text = ClipGet()
If $text <> "" Then
$folders = StringSplit($text, @LF, 1)
If @error Then
$terminalFolder = $folders[1]
$dirs = StringSplit($terminalFolder, "\", 1)
If @error Then Return
$x = $dirs[0]
Do
$y = $x - 1
While $dirs[$y] = $dirs[$x]
$y -= 1
WEnd
If $y = $x - 1 Then
$x -= 1
$terminalFolder = BuildPath($x)
ContinueLoop
EndIf
$rootFolder = BuildPath($y + 1)
$terminalFolder = BuildPath($x)
ExitLoop
Until $x = 0
If $x > 0 Then
_SoundPlay("ok.wav")
ShellExecute("C:\Program Files\FreeCommander\FreeCommander.exe", $rootFolder & " " & $terminalFolder)
Else
_SoundPlay("fail.wav")
EndIf
EndIf
EndIf
EndFunc   ;==>ClipFolders

Func BuildPath($arrayIndex)
Local $path = ""
For $i = 1 To $arrayIndex
$path &= $dirs[$i] & "\"
Next
Return _FileDirNoSlash($path)
EndFunc   ;==>BuildPath

; Return Directory part of path without trailing slash
Func _FileDirNoSlash($path)
Return StringLeft($path, StringInStr($path, "\", 0, -1) - 1)
EndFunc   ;==>_FileDirNoSlash

I included the .wav files or you can just comment out the sound play calls.



IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 6,137
  • Slartibartfarst
    • View Profile
    • Donate to Member
Re: IDEA: Quickly remove redundant recursive folders
« Reply #2 on: November 29, 2011, 11:46:39 PM »
If I understand the OP correctly, then I think you should be able to do exactly what you want using xplorer² - I think the free/trial version might be OK for your purposes.
It is something that I need to periodically do to tidy up document repositories on main disk and backup stores.

All you do in xplorer² is select the topmost folder of the nested folder set, enter (go into) that folder, then do a search (Ctrl-F) on wildcard filename "*.*" (i.e., all files). One option is to choose to search "depth first" or "breadth first".

xplorer² then gives you a flat-file listing in a "scrap container" - e.g., as per the screenshot below, where I did the search on the Windows directory (but stopped it after a few seconds as the search would have gone on for ages).
In the scrap container, there you can have any column you need. One is a column named Path by default (or choice), which displays the full path of every file found in the nested folders.
The screenshot was taken after I had sorted the searched files on the Path column, and shows the path to the subfolders where the files are located.

Once you have done that search, you can treat the files listed as files. Thus, you can open or (in this case) move/copy any of the files from the container by selecting them and moving them or copy/pasting them into whatever drive/folder you want. This removes them or copies them from their previous/original path.

xplorer² has robust copy and move functions, so I prefer to use that when moving data around like this.
Scrap containers can be treated like files themselves, and provide some incredible versatility for file management.

Hope this helps or is of use.
Screenshot - 2011-11-30 , 18_39_18.png
« Last Edit: November 29, 2011, 11:53:17 PM by IainB »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,406
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: IDEA: Quickly remove redundant recursive folders
« Reply #3 on: November 30, 2011, 12:40:17 AM »
Quote
I don't really want to muck about deleting folders on your system.

Wise decision -- this is one of those areas it pays to be paranoid.

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,283
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: IDEA: Quickly remove redundant recursive folders
« Reply #4 on: November 30, 2011, 02:29:09 PM »
Ok, I've made this a bit more usable.

Uses Explorer windows rather than relying on a file manager.

There are 2 scenarios

a) you have a chain with dupes such as
c:\temp\temp\temp\data


Select the data folder in Explorer, a file manager or a search window
such as Everything Search.

press Shift-F8 hotkey.

Explorer windows will come up side by side
one side will be
c:\temp

the other side will be
c:\temp\temp\temp

so that you can drag "data" to the other folder's top temp folder
then delete the superfluous temp that's next to it.

b) the selected folder at that end of a chain of dupes with
no differently named folder at the end such as
c:\temp\temp\temp etc..

Highlight the last temp in the chain and press Shift-F8.

2 Explorer windows will open side by side.
One will have the folder above the first temp as in c:\
the other will have one folder above the last temp

What you do in this case is drag the terminal temp folder
onto the desktop as a move.  Now you can delete the top
temp folder from the other Explorer window without deleting
your data.

Then drag the temp folder from the desktop into the c:\ folder.

Note that it is up to you to determine if all the intermediate folders
are empty.

Note: If the window you used to select the folder before pressing the
hotkey was an Explorer window, it is closed as soon as the folder name
is captured. This is because it can interfere with folders being set up
side by side.  If it's not an Explorer window, such as Everything Search
of some file manager, it's left alone.

The Explorer windows are opened leaving a gap by the taskbar to make it
easier to drag the folder to desktop if needed.


Requirements

Windows XP or later

"Display full path in title bar" enabled in Folder Options.

Taskbar AutoHide disabled.

Utility tested on English Language Windows only.

Also the .wav files ok.wav and fail.wav should be in the same folder
as DupFolder.exe


The attached zip includes the exe and 2 wav files.



magician62

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 118
    • View Profile
    • Donate to Member
Re: IDEA: Quickly remove redundant recursive folders
« Reply #5 on: December 07, 2011, 02:10:05 AM »
I believe that the removal of redundant folders is already included in WinRAR from version 3.90, so if the OP is using WinRAR

Options > Settings >Compression - Remove redundant folders from extraction path

justW3

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 11
  • What you think I said is probably not what I meant
    • View Profile
    • Donate to Member
Re: IDEA: Quickly remove redundant recursive folders
« Reply #6 on: December 16, 2011, 03:03:47 AM »
Sorry for being absent from this discussion (I've been away), and thanks for all the suggestions. I think I'll try them all to see which one I prefer. Thanks to one and all for your input.  :Thmbsup: