China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-07-02 21:06
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to implement the function of calling a bat file through the right-click menu to move files View 2,897 Replies 43
Floor 31 Posted 2008-02-07 23:46 ·  中国 吉林 吉林市 联通
中级用户
★★
Credits 307
Posts 130
Joined 2008-02-01 21:29
18-year member
UID 109981
Gender Male
Status Offline
Originally posted by slore at 2008-2-6 12:54 PM:
I am using AllFileSystemObject above

What the 17th floor said is correct. If you use * to apply to files, to apply to folders you need to use or folder, but you cannot use directory and folder at the same time. Using AllFileSystemObject can apply to both files and folders.
The registry is really picky, it has to ensure both comprehensive functions and no redundancy and overlap in the key values!
What is the parameter format and function of "%%~dpnxi" in the line "call :sub1 "%%~dpnxi""?
Floor 32 Posted 2008-02-07 23:51 ·  中国 吉林 吉林市 联通
中级用户
★★
Credits 307
Posts 130
Joined 2008-02-01 21:29
18-year member
UID 109981
Gender Male
Status Offline
What the person upstairs said about the log function, I also completely don't know how to do it. I'm too inexperienced.
There are still many grammatical errors in what I write, and I'm not familiar with the syntax of batch processing.
For example, can the jump label within the scope of the for statement be recognized?
Floor 33 Posted 2008-02-08 00:00 ·  中国 吉林 吉林市 联通
中级用户
★★
Credits 307
Posts 130
Joined 2008-02-01 21:29
18-year member
UID 109981
Gender Male
Status Offline
Why can directly selecting a folder achieve moving up, but selecting a folder cannot? It's also plagiarizing sub1, headache
Floor 34 Posted 2008-02-08 11:36 ·  中国 吉林 吉林市 联通
中级用户
★★
Credits 307
Posts 130
Joined 2008-02-01 21:29
18-year member
UID 109981
Gender Male
Status Offline
I used the 'dir /b' mentioned by the person above, and it worked successfully. I can extract shelled files and folders, and it's a success. I've learned a lot. Now I'll post the complete batch again for everyone to use.

Installation program
@echo off

call :%* 2>nul || goto setup
goto :eof

:Sub1
rem Move to parent directory
if not defined str set "str=%~nx1"
if not exist "..\%~nx1" (move "%str%" "..\%~nx1" && set "str=" && goto :eof)
call :Sub1 "%~n1_New%~x1"
goto :eof

:Sub2
rem Unshell
cd "%~1"
for /f "delims=" %%i in ('dir /b') do call :Sub1 "%%~dpnxi"

goto :eof



:setup
reg add "hkcr\AllFilesystemObjects\shell\Move to Parent Directory\command" /f /t reg_sz /v "" /d "\"%~0\" Sub1 \"%%1\""
reg add "hkcr\directory\shell\Unshell\command" /f /t reg_sz /v "" /d "\"%~0\" Sub2 \"%%1\""

goto :eof

Uninstallation program
reg delete "hkcr\directory\shell\Unshell" /f
reg delete "hkcr\AllFilesystemObjects\shell\Move to Parent Directory" /f
Floor 35 Posted 2008-02-08 12:16 ·  印度 马哈拉施特拉邦 孟买郊区县 腾讯云
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
Very Good!
However, just using dir /b cannot copy hidden files. Also, why not put the uninstall part in the setup? In it, judge whether there are relevant registry items and then decide whether to install or uninstall.
The most important thing is how much you have gained in this post? Can you write code with your own style based solely on the idea without looking at the reference?
For example, what is the actual reason for the problem mentioned in your previous 12F? What is the connection between the content of the value in the registry and the batch processing? Why are there quotes in some places and not in others?
You can try to solve these problems by yourself. If you don't understand something, you can post a reply to seek hints.
Floor 36 Posted 2008-02-08 13:34 ·  中国 吉林 吉林市 联通
中级用户
★★
Credits 307
Posts 130
Joined 2008-02-01 21:29
18-year member
UID 109981
Gender Male
Status Offline
@echo off
call :%* 2>nul || goto choice
goto :eof

:Sub1
rem Move to parent directory
if not defined str set "str=%~nx1"
if not exist "..\%~nx1" (move "%str%" "..\%~nx1" && set "str=" && goto :eof)
call :Sub1 "%~n1_New%~x1"
goto :eof

:Sub2
rem Unpack
pushd "%~1"
for /f "delims=" %%i in ('dir /a /b') do call :Sub1 "%%~dpnxi"
popd
rd "%~1"
goto :eof

:choice
set /p dd=Install A, Uninstall X, Exit T:
if "%dd%"=="a" goto setup
if "%dd%"=="A" goto setup
if "%dd%"=="x" goto unistall
if "%dd%"=="X" goto unistall
if "%dd%"=="t" goto :eof
if "%dd%"=="T" (goto :eof) else echo Re-enter &goto choice
goto :eof

:setup
reg add "hkcr\AllFilesystemObjects\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

:unistall
reg delete "hkcr\directory\shell\Unpack" /f
reg delete "hkcr\AllFilesystemObjects\shell\Move to Parent Directory" /f
goto :eof

Now the uninstall is also added, and the /a parameter is added to dir.

I still don't know the usage of call in this text, and how %1 is passed in the registry and batch processing.
Floor 37 Posted 2008-02-08 13:41 ·  中国 吉林 吉林市 联通
中级用户
★★
Credits 307
Posts 130
Joined 2008-02-01 21:29
18-year member
UID 109981
Gender Male
Status Offline
Adding dir /a /b still can't move hidden files
Floor 38 Posted 2008-02-08 13:50 ·  中国 吉林 吉林市 联通
中级用户
★★
Credits 307
Posts 130
Joined 2008-02-01 21:29
18-year member
UID 109981
Gender Male
Status Offline
Can the two sentences "if "%dd%"=="a" goto setup" and "if "%dd%"=="A" goto setup" be written as one sentence?
Floor 39 Posted 2008-02-08 15:59 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Floor 40 Posted 2008-02-08 17:17 ·  中国 吉林 吉林市 联通
中级用户
★★
Credits 307
Posts 130
Joined 2008-02-01 21:29
18-year member
UID 109981
Gender Male
Status Offline
I've figured out a problem. When running a batch file, you can add parameters. When calling a subroutine with the call label, you can also add parameters.
Floor 41 Posted 2008-02-08 17:23 ·  中国 吉林 吉林市 联通
中级用户
★★
Credits 307
Posts 130
Joined 2008-02-01 21:29
18-year member
UID 109981
Gender Male
Status Offline
An important issue for beginners to learn
It seems that after /?, you are not familiar with the format of the application command
For example
if "%dd%"=="a" goto setup
Can the two sentences if "%dd%"=="A" goto setup be written as one sentence?
This problem
I used if "%dd%"=="a" ^| "%dd%"=="A" goto setup
The syntax is incorrect ah
Floor 42 Posted 2008-02-08 18:00 ·  中国 吉林 吉林市 联通
中级用户
★★
Credits 307
Posts 130
Joined 2008-02-01 21:29
18-year member
UID 109981
Gender Male
Status Offline
Is there really no logical operator without the assignment function? The previous question can be solved with the /i parameter. Can we use one statement to judge that the value of dd is equal to one of a, b, c to meet the condition?
Floor 43 Posted 2008-02-08 18:22 ·  印度 马哈拉施特拉邦 孟买郊区县 腾讯云
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline

:choice
set /p dd=Install A, Uninstall X, Exit T:
call :%dd% || (echo error! && goto choice)
goto :eof

:a
:A
reg .....
goto :eof

:x
:X
reg .....
goto :eof

Why is there still interaction?
In the setup, first test if there is installation information in the registry. If there is, uninstall automatically; if not, install automatically. The structure should be clearer and more straightforward.
Floor 44 Posted 2008-02-09 12:42 ·  中国 吉林 吉林市 联通
中级用户
★★
Credits 307
Posts 130
Joined 2008-02-01 21:29
18-year member
UID 109981
Gender Male
Status Offline
Thanks to the great support of 3742668, if you hadn't helped me write it, I couldn't have done it. In short, it's a complete success! It's even better than I expected!! Thanks again to 3742668!!
Forum Jump: