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 09, 2016, 03:30:57 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: [Complete] Consolidate files in the parent folder  (Read 9080 times)

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 7,986
    • View Profile
    • Dales Computer Services
    • Donate to Member
[Complete] Consolidate files in the parent folder
« on: March 12, 2009, 07:04:28 PM »
I have an odd problem that I need to solve and I am not sure how to solve it.

There may be a simple tool in Windows or a function in DOpus that can achieve this but I haven't found it.

I have a folder full of many subfolders (actually a number of these folder structures) and each subfolder contains files.

All the file names are unique and I would like to move all the files up a level into the parent folder and then delete all the empty subfolders. Like this:

Before:

Folder
 .
SubFolder 1   ... SubFolder 2 .... etc
 .
File1                 File 2              etc.


After:

Folder
 .
File 1    Files 2  etc


I have tried using a command line but you can't use wild cards for folder names.

Anyone got any ideas?
« Last Edit: March 13, 2009, 05:05:41 AM by Carol Haynes »

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,606
    • View Profile
    • Donate to Member
Re: [Request] Consolidate files in the parent folder
« Reply #1 on: March 12, 2009, 07:57:37 PM »
you could try this...

fileselectfolder,MyFold,::{20d04fe0-3aea-1069-a2d8-08002b30309d}

loop, %myfold%\*.*,0,1
{
If a_loopfiledir <> %myfold%
filemove, %a_loopfilefullpath%,%myfold%
}

loop, %myfold%\*.*,2,1
fileremovedir, %a_loopfilefullpath%,1

exitapp

prompts for a folder, then moves all files from the subfolders to the root (files in subfolders are identified as having a different directory path than those in the root), then deletes all the subfolders

there are probably more elegant solutions, but this was quick - a brief tests indicates it works as advertised (though maybe best to test it for yourself...)

EDIT: simplified the code
« Last Edit: March 15, 2009, 05:45:02 PM by Target »

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 7,986
    • View Profile
    • Dales Computer Services
    • Donate to Member
Re: [Request] Consolidate files in the parent folder
« Reply #2 on: March 12, 2009, 08:40:24 PM »
Thanks I will give it a try in the morning

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,421
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: [Request] Consolidate files in the parent folder
« Reply #3 on: March 12, 2009, 08:42:11 PM »
i'm, sure you've thought of this carol but one worry is what happens if different files with same name are located in different subdirectories.

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 7,986
    • View Profile
    • Dales Computer Services
    • Donate to Member
Re: [Request] Consolidate files in the parent folder
« Reply #4 on: March 12, 2009, 08:58:10 PM »
That wasn't the problem in the case - all the file names were unique.

Couldn't wait until morning - works great. Exactly what I needed in this case ;)

A few pennies winging there way and on Target  :-* :-* :-*

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,606
    • View Profile
    • Donate to Member
Re: [Request] Consolidate files in the parent folder
« Reply #5 on: March 12, 2009, 09:13:41 PM »
you're most welcome Carol!!

i did consider what Mouser said, but you'd already said the filenames were all unique (I could change it to cater for that if you want...)

and thanks for the credits (not necessary, but appreciated)

exold

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 10
  • Do nothing. Time is too precious to waste.
    • View Profile
    • Exold
    • Read more about this member.
    • Donate to Member
Re: [Complete] Consolidate files in the parent folder
« Reply #6 on: March 31, 2009, 05:18:26 AM »
If you're trying to do this somewhere you only have access to CMD.EXE, I'm pretty sure you can use FOR..IN..DO to get the job done. It's a little-known tool that provides a lot of powerful functionality. The UI is crap, though.... :P
---
David A. P.
Ars Arboris -- Art of the Tree.

bootz15

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 17
    • View Profile
    • Donate to Member
Re: [Complete] Consolidate files in the parent folder
« Reply #7 on: April 05, 2009, 01:54:23 PM »
This is awesome! I would really like to see the code that assumes the sub-files are not uniquely named, too.

Ampa

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 592
  • I am cute ;)
    • View Profile
    • MonkeyDash - 2 Player strategy boardgame
    • Donate to Member
Re: [Complete] Consolidate files in the parent folder
« Reply #8 on: April 06, 2009, 08:56:09 AM »
In Xplorer2 you can flatten a folder structure by selecting the folder and pressing Shift+Enter. This shows all files within the folder and subfolders in a single pane, at which point you can move / rename or do anything else with them.

Perhaps DOpus has something similar?

vixay

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 140
  • ViXaY
    • View Profile
    • Donate to Member
Re: [Complete] Consolidate files in the parent folder
« Reply #9 on: July 15, 2009, 05:42:16 AM »
I have done some more modifications to suit my purpose, which was to rename the files to include the folder path it had.
i.e.
Quote
root
 a
   1
 b
   1
   2
would become
Quote
root
a-1
b-1
b-2

here's the code for it
FlattenWithFolderNames.ahk
fileselectfolder,MyFold,::{20d04fe0-3aea-1069-a2d8-08002b30309d}
SetWorkingDir, %MyFold%
loop, *.*,0,1
{
parentpath := RegExReplace(A_LoopFileDir,"\\","-")
;StringReplace, parentpath, A_LoopFileDir, \,-,All
newname = %parentpath%-%A_LoopFileName%
;msgbox %newname%
If a_loopfiledir <>
filemove, %a_loopfilefullpath%,%newname%
}

loop, %myfold%\*.*,2,1
fileremovedir, %a_loopfilefullpath%,1

exitapp
"Drunk on the Nectar of Life!" -me

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 7,986
    • View Profile
    • Dales Computer Services
    • Donate to Member
Re: [Complete] Consolidate files in the parent folder
« Reply #10 on: July 15, 2009, 06:31:24 AM »
Neat idea which should avoid naming conflicts