![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-09-27 03:01 |
47,813 topics / 349,918 posts / today 0 new / 48,276 members |
| DOS批处理 & 脚本技术(批处理室) » How to implement the function of calling a bat file through the right-click menu to move files |
| Printable Version 3,503 / 43 |
| Floor16 3742668 | Posted 2008-02-06 12:44 |
| 荣誉版主 Posts 718 Credits 2,013 | |
Originally posted by pinghu at 2008-2-5 21:48: 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) |
|
| Floor17 slore | Posted 2008-02-06 12:54 |
| 铂金会员 Posts 2,478 Credits 5,212 | |
|
The above * I'm using AllFileSystemObject
|
|
| Floor18 pinghu | Posted 2008-02-06 15:06 |
| 中级用户 Posts 130 Credits 307 | |
|
The problem has been initially solved, and I can breathe a sigh of relief!
Thanks to the support of 3742668, I learned the usage of sub1, reg add and setting str variables from it Thank you very much!! |
|
| Floor19 pinghu | Posted 2008-02-06 18:10 |
| 中级用户 Posts 130 Credits 307 | |
|
There is a problem when running the script for 3742668. Suppose the file name I selected is 1.txt, and when moving up, a 1.txt file appears in the parent directory. I rebuild the 1.txt file, then move up again, and a 1_New.txt file appears in the parent directory. I create the 1.txt file again, then move up again, and it fails!
|
|
| Floor20 pinghu | Posted 2008-02-06 18:24 |
| 中级用户 Posts 130 Credits 307 | |
|
To be precise, it entered an infinite loop
|
|
| Floor21 pinghu | Posted 2008-02-06 18:42 |
| 中级用户 Posts 130 Credits 307 | |
|
I improved the code and solved the infinite loop
@echo off call :%* 2>nul || goto setup goto :eof :Sub1 rem Move to parent directory set "str=%~nx1" set /a counter=1 :loop if not exist "..\%str%" goto Next set "str=%~n1_New%counter%%~x1" set /a counter+=1 goto loop :Next set /a counter= move "%~nx1" "..\%str%" goto :eof :Sub2 rem Unpack rem Complete it 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 But what about when it comes to folders? |
|
| Floor22 vkill | Posted 2008-02-06 21:15 |
| 金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽 | |
|
Adding a right - click also only allows single files to be used
|
|
| Floor23 pinghu | Posted 2008-02-06 21:54 |
| 中级用户 Posts 130 Credits 307 | |
|
@echo off
call :%* 2>nul || goto setup goto :eof :Sub1 rem Move to parent directory set "str=%~nx1" set /a counter=1 :loop if not exist "..\%str%" goto Next set "str=%~n1_New%counter%%~x1" set /a counter+=1 goto loop :Next set /a counter= move "%~nx1" "..\%str%" goto :eof :Sub2 rem Unpack setlocal enabledelayedexpansion set /a counter=1 cd /d "%1" for /f "delims=" %%i in (*.*) do ( if not exist "..\%%~nxi" goto Next :loop set "str=%%~ni_New!counter!%%~xi" set /a counter+=1 if not exist "..\!str!" goto Next goto loop :Next if "!counter!" equ "1" (move "%%i" "..\%%~nxi") else move "%%i" "..\!str!" set /a counter=1) set counter= goto :eof :setup reg add "hkcr\*\shell\Move to Parent Directory\command" /f /t reg_sz /v "" /d "\"%~0\" Sub1 \"%%1\"" reg add "hkcr\directory\shell\Move to Parent Directory\command" /f /t reg_sz /v "" /d "\"%~0\" Sub1 \"%%1\"" reg add "hkcr\directory\shell\Unpack\command" /f /t reg_sz /v "" /d "\"%~0\" Sub2 \"%%1\"" goto :eof Tested, the function of Sub1 can support all selected files and folders and ensure the reliability of renaming. It's just that Sub2 is still wrong. Hope everyone can help. Really don't know where the mistake is, I'm really confused when writing this Sub2. Hope everyone can find the error |
|
| Floor24 pinghu | Posted 2008-02-07 02:16 |
| 中级用户 Posts 130 Credits 307 | |
|
Found that there are duplicate tags. After correcting, sub2 still cannot be used. Notify me and I don't know what way to open it. Depressed
|
|
| Floor25 3742668 | Posted 2008-02-07 02:33 |
| 荣誉版主 Posts 718 Credits 2,013 | |
|
Why rewrite so much code when there's already sub1? It's still suggested to use VBS or other more rigorous scripts to implement.
[ Last edited by 3742668 on 2008-2-7 at 01:26 PM ] |
|
| Floor26 pinghu | Posted 2008-02-07 12:28 |
| 中级用户 Posts 130 Credits 307 | |
|
I can't do VBS, I only know batch processing. The script upstairs has been tested, and both functions don't work. What's the matter? Where exactly is the mistake in my Sub2?
|
|
| Floor27 3742668 | Posted 2008-02-07 13:07 |
| 荣誉版主 Posts 718 Credits 2,013 | |
|
Sorry, because there is no test environment, there are many errors in the code on floor 25, including logical errors and grammatical errors.
Hehe, it's been too long since I wrote it, my hands are rusty. Try the following: It is recommended to select the operation targets in batches at one time for testing and see if there will be synchronization problems. In addition, you can add the function of writing logs after move. |
|
| Floor28 pinghu | Posted 2008-02-07 17:13 |
| 中级用户 Posts 130 Credits 307 | |
|
After several trial attempts, it was found that the "Move to parent directory" function supports all files and folders. The "Unpack" function can only be applied to the files in the selected folder, and cannot be applied to the folders in the selected folder.
|
|
| Floor29 pinghu | Posted 2008-02-07 18:32 |
| 中级用户 Posts 130 Credits 307 | |
|
The above code plus
reg add "hkcr\Folder\shell\Move to Parent Directory\command" /f /t reg_sz /v "" /d "\"%~0\" Sub2 \"%%1\"" can move the directory |
|
| Floor30 3742668 | Posted 2008-02-07 19:00 |
| 荣誉版主 Posts 718 Credits 2,013 | |
Originally posted by pinghu at 2008-2-7 17:13: I only take charge of giving you hints and frameworks. The specific start and end still need to be written by yourself according to your own ideas. For example, as mentioned above, it is suggested to add a log function and try operations with extremely large quantities. In addition, if you want the unpack function to be applied to folders, you can try to solve it with dir /b by yourself. It is suggested that you rewrite it from the beginning to the end according to your own ideas. Only in this way can you gain something. This is also the significance of the forum. |
|
| Prev 1 2 3 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |