2

I found several such questions and tried to adapt the answers to my needs but no luck so far. I'm trying to create two context menu entries in Windows 7 that would:

  1. Move all files from subfolders in a given folder to the parent folder. Duplicates should be renamed to Filename-Duplicate but not deleted.
  2. Delete all empty subfolders.

I was able to successfully create the needed entries in:

HKEY_CLASSES_ROOT\Directory\shell\Delete Empty Subfolders\command

and

HKEY_CLASSES_ROOT\Directory\shell\Move all subfiles here\command

The commands (and I think here lies the problem) are as follows for the two:

for /r ROOT %%d in (*.*) do move "%%d" "%1\"
for /f "delims=" %%d in ('dir /s /b /ad ^| sort /r') do rd "%%d"

When I select a folder that I created for testing this and select either one from the context menu it seems the batch file on disk where the Registry entry points to is found and executed but with no result.

I think the problem is the commands themselves. I'm not very experienced with FOR either. If this can be accomplished with PowerShell I'm open to that option. If at all possible I would avoid using external dependencies such as 3rd party apps to execute the commands.

1

1 Answer 1

0

The problem is not with your command. Instead it is related to the Registry because when you do it like this Windows will start looking for a program called for.exe

HKCU\Software\Microsoft\Windows\CurrentVersion\App Paths\for.exe
HKCU\Software\Microsoft\Windows\CurrentVersion\App Paths\for.exe

and then it starts looking for your program for.* in System32 and the Windows directories. When this fails it returns an error.

As a beginning try to make a .bat file and put your commands in it. In the Registry try to refer to the full path of your batch file.

P.S: You will have another problem with long file names.

4
  • That's what im doing already but it's not working but it doesent throw any error either. Just silently fails. Image: i.imgur.com/IjKgmqW.jpg
    – TMRW
    Commented Aug 21, 2014 at 13:58
  • 1
    remove all the double quotes from the image
    – M. A.
    Commented Aug 21, 2014 at 14:35
  • try to catch the log with Process Monitor and search your command line file and continue tracing
    – M. A.
    Commented Aug 21, 2014 at 14:43
  • Ok. Some progress. Removed double quotes from both registry values as you suggested and tweaked the commands themselves a bit. Now empty folders are removed and it appears to work correctly. The problem was DIR /S flag. As for moving files to parent folder it works but duplicates are overwritten and result is a single copy. And what about those long filenames?
    – TMRW
    Commented Aug 22, 2014 at 13:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .