Move files from subfolder to parent folder

I have this c:\test\folder1\subfolder1\file1.txt and c:\test\folder2\subfolder2\file2.txt.
I need to :

  • move files file1.txt to folder1 and file2.txt to folder2
  • delete subfolder1 and subfolder2

If possible I want to do this by selecting folder1 and folder2.

It's possible to do this with DO's command or I need to use vbscript.

I don't think DOpus will do this sort of rename/move without going into flat view.

Its easy enough to do with standard *nix tools (so I wouldn't waste time creating a special script for this when you can just install a tool set and use those):

find folder1 folder2 -type f -print0 | xargs -0 mv -t .

You can create a button for this. Ask if you want more help.

I wrote script to move files from subfolders to root selected folders...


Select some folders and clic button...

<?xml version="1.0"?>
<button backcol="none" display="both" textcol="none">
 <label>Files2Root</label>
 <tip>Move files to root folders</tip>
 <icon1>#move</icon1>
 <function type="normal">
  <instruction>@nodeselect</instruction>
  <instruction>@confirm Do you want to move all files to root folders ?|Yes|No</instruction>
  <instruction />
  <instruction>Rename PATTERN * TO *</instruction>
  <instruction />
  <instruction>@script vbscript</instruction>
  <instruction>Dopus.OutputString &quot;Script: Files2Root - By Albator V&quot;</instruction>
  <instruction>Dim ParentPath</instruction>
  <instruction />
  <instruction>Function Rename_GetNewName ( strFileName, strFullPath, fIsFolder, strOldName, ByRef strNewName )</instruction>
  <instruction> If fIsFolder then</instruction>
  <instruction>  ParentPath = strFullPath &amp; &quot;\&quot; &amp; strFileName</instruction>
  <instruction>  Set objFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)</instruction>
  <instruction>  Set objFolder = objFSO.GetFolder(ParentPath) </instruction>
  <instruction>  Set colSubfolders = objFolder.Subfolders</instruction>
  <instruction />
  <instruction>  For Each objSubfolder in colSubfolders </instruction>
  <instruction>   FolderLoop(ParentPath &amp; &quot;\&quot; &amp; objSubfolder.Name) </instruction>
  <instruction>  Next </instruction>
  <instruction />
  <instruction>  Set colSubfolders = Nothing </instruction>
  <instruction>  Set objFolder = Nothing </instruction>
  <instruction>  Set objFSO = Nothing</instruction>
  <instruction> Else</instruction>
  <instruction>  Dopus.OutputString &quot;Select first some folders.&quot;</instruction>
  <instruction> End If</instruction>
  <instruction>End Function </instruction>
  <instruction />
  <instruction>Function FolderLoop(Path) </instruction>
  <instruction> Set objFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)</instruction>
  <instruction> Set objFolder1 = objFSO.GetFolder(Path) </instruction>
  <instruction> Set colSubfolders1 = objFolder1.Subfolders </instruction>
  <instruction> Set colFiles = objFolder1.Files </instruction>
  <instruction> </instruction>
  <instruction> For Each objFile in colFiles </instruction>
  <instruction>  Fichier = Path &amp; &quot;\&quot; &amp; objFile.Name</instruction>
  <instruction>  objFSO.MoveFile Path &amp; &quot;\&quot; &amp; objFile.Name, ParentPath &amp; &quot;\&quot; </instruction>
  <instruction>  Dopus.OutputString &quot;Move &quot; &amp; fichier</instruction>
  <instruction>   Dopus.OutputString &quot;to &quot; &amp; ParentPath</instruction>
  <instruction> Next </instruction>
  <instruction />
  <instruction> For Each objSubfolder1 in colSubfolders1 </instruction>
  <instruction>  FolderLoop(Path &amp; &quot;\&quot; &amp; objSubfolder1.Name) </instruction>
  <instruction> Next </instruction>
  <instruction />
  <instruction> objFSO.DeleteFolder(Path) </instruction>
  <instruction> Dopus.OutputString &quot;Delete &quot; &amp; Path</instruction>
  <instruction> Set colSubfolders1 = Nothing </instruction>
  <instruction> Set objFolder1 = Nothing </instruction>
  <instruction>End Function </instruction>
 </function>
</button>

I know this an old post but for future reference this may be useful...

I was searching to solve the same problem, after a bit of trial and error I've created a button with the following function:

Copy MOVE TO={filepath$|..\..}

This seems to work fine on multiple selections within 'Grouped' view, very useful when paired with filtered selections and a lot simpler than using a vbs.

Yes, but your script don't solved my original request.
Your command move up selected files, my request was : move up files that are in subfolders of selected folders.