Originally posted by pinghu at 2008-2-5 21:48:
It seems that everyone hasn't attached importance to my post yet. I think it's because everyone thinks the difficulty lies in the renaming. Moving files seems easy, but when you test it personally, you will find that when you select several files,...
@echo off
call :%* 2>nul || goto setup
goto :eof
:Sub1
rem Move to parent directory
set "str=%~nx1"
:loop
if not exist "..\%str%" goto Next
set "str=%~n1_New%~x1"
goto loop
:Next
move "%~nx1" "..\%str%"
goto :eof
:Sub2
rem Unpack
rem Complete by yourself
goto :eof
:setup
reg add "hkcr\*\shell\Move to Parent Directory\command" /f /t reg_sz /v "" /d "\"%~0\" Sub1 \"%%1\""
reg add "hkcr\Folder\shell\Unpack\command" /f /t reg_sz /v "" /d "\"%~0\" Sub2 \"%%1\""
goto :eof
The above is just a demo script. You can install it automatically by double-clicking.
Note that the setup part only adds the "Move to Parent Directory" function on files, and does not process folders. This can be added by yourself.
In addition, the above script does not handle the synchronization problem when multiple files are selected at the same time. It may cause the problem of overwriting with the same name. For this situation, you can appropriately use a temporary file to set an identifier, so that each instance can decide whether to copy according to the situation. For example, you can write the currently processed file name into a certain file, remember to use the overwrite mode, then delay for a period of time, then read the flag file, and the file name corresponding to the obtained one will perform the moving work. After moving, change the flag file, and those that do not match will continue to wait. Continue to query the flag file....
It is really not of much significance to complete it with pure bat. If possible, I suggest you try vbs, which will be much simpler.
In addition, here are a few links that may be useful:
SendTo + Batch Practical Small Tool -- Enhanced Version Send To
Find all bat files in the computer and copy them to the current directory?
How to add right-click menu in batch processing?
SendTo + (VBS Version)
