|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 16 楼』:
使用 LLM 解释/回答一下
Originally posted by pinghu at 2008-2-5 21:48:
看来各位还未重视我的帖子,我想是因为大家认为难就难在重命名上面,移动文件看起来很容易,等你亲自测试的时候就会发现,当选中若干文件时, ...
@echo off
call :%* 2>nul || goto setup
goto :eof
:Sub1
rem 移动到父目录
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 脱壳
rem 自己完成
goto :eof
:setup
reg add "hkcr\*\shell\移至父目录\command" /f /t reg_sz /v "" /d "\"%~0\" Sub1 \"%%1\""
reg add "hkcr\Folder\shell\脱壳\command" /f /t reg_sz /v "" /d "\"%~0\" Sub2 \"%%1\""
goto :eof
上面只是个演示脚本,双击后就可自动安装了。
注意setup部分只在文件上面添加"移动至父目录"功能,并未对文件夹做处理,这个可以自己添加.
另外,上面的脚本也没有对同时选中多个文件的同步问题进行处理, 可能导致会出现同名覆盖的问题,对于这种情况,可以适当地利用临时文件设置一下标识,使每个实例运行的时候能根据情况决定是否拷贝。例如可以向某个文件中写入当前处理的文件名,记得用覆盖模式,然后延时一段时间,接着读取标志文件,文件名对应得到的就执行移动工作,移动完后更改标志文件,对不上的则继续等待.继续查询标志文件。...
用纯粹的bat来完成真的是没多大意义,如果可能,我建议你还是尝试一下vbs,会简单得多。
另外给你几个链接可能有用:
SendTo+批处理实用小工具--加强版发送到
查找电脑中,所有的bat文件,并复制到当前目录?
批处理如何添加右键菜单?
SendTo+(VBS版)
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)
|
|
2008-2-6 12:44 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 17 楼』:
使用 LLM 解释/回答一下
上面的*我用的是 AllFileSystemObject
The above * I'm using AllFileSystemObject
|
|
2008-2-6 12:54 |
|
|
pinghu
中级用户
  
积分 307
发帖 130
注册 2008-2-1
状态 离线
|
『第 18 楼』:
使用 LLM 解释/回答一下
问题得到初步解决,可以松一口气了!
感谢3742668的支持,我从中学习了sub1和reg add 和设置str变量的用法
ありがとございます!!
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!!
|
|
2008-2-6 15:06 |
|
|
pinghu
中级用户
  
积分 307
发帖 130
注册 2008-2-1
状态 离线
|
『第 19 楼』:
使用 LLM 解释/回答一下
3742668的脚本运行时有个问题
假设我选的文件名为1.txt,往上移动,上级目录出现了一个1.txt文件
我重建1.txt文件,再往上移动,上级目录出现了1_New.txt文件
我再次新建1.txt文件,再往上移动,失败!!
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!
|
|
2008-2-6 18:10 |
|
|
pinghu
中级用户
  
积分 307
发帖 130
注册 2008-2-1
状态 离线
|
『第 20 楼』:
使用 LLM 解释/回答一下
确切的说是进入死循环了
To be precise, it entered an infinite loop
|
|
2008-2-6 18:24 |
|
|
pinghu
中级用户
  
积分 307
发帖 130
注册 2008-2-1
状态 离线
|
『第 21 楼』:
使用 LLM 解释/回答一下
我把代码改进了一下,解决了死循环
@echo off
call :%* 2>nul || goto setup
goto :eof
:Sub1
rem 移动到父目录
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 脱壳
rem 自己完成
goto :eof
:setup
reg add "hkcr\*\shell\移至父目录\command" /f /t reg_sz /v "" /d "\"%~0\" Sub1 \"%%1\""
reg add "hkcr\Folder\shell\脱壳\command" /f /t reg_sz /v "" /d "\"%~0\" Sub2 \"%%1\""
goto :eof
可遇到文件夹怎么办呢?
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?
|
|
2008-2-6 18:42 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 22 楼』:
使用 LLM 解释/回答一下
加右键也只是单文件可以用
Adding a right - click also only allows single files to be used
|
|
2008-2-6 21:15 |
|
|
pinghu
中级用户
  
积分 307
发帖 130
注册 2008-2-1
状态 离线
|
『第 23 楼』:
大侠帮忙看看,sub2部分哪里语法不对
使用 LLM 解释/回答一下
@echo off
call :%* 2>nul || goto setup
goto :eof
:Sub1
rem 移动到父目录
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 脱壳
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\移至父目录\command" /f /t reg_sz /v "" /d "\"%~0\" Sub1 \"%%1\""
reg add "hkcr\directory\shell\移至父目录\command" /f /t reg_sz /v "" /d "\"%~0\" Sub1 \"%%1\""
reg add "hkcr\directory\shell\脱壳\command" /f /t reg_sz /v "" /d "\"%~0\" Sub2 \"%%1\""
goto :eof
经测试,sub1的功能可以支持到所有选定的文件和文件夹,并保证重命名的可靠性,只是sub2还有不对的地方,望大家帮忙
到底错在哪里呢,我写这个sub2头都大了,望大家挑错
@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
|
|
2008-2-6 21:54 |
|
|
pinghu
中级用户
  
积分 307
发帖 130
注册 2008-2-1
状态 离线
|
『第 24 楼』:
使用 LLM 解释/回答一下
发现标签重名,改正后sub2仍然不能使用,通知我不知道用什么方式打开,郁闷了
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
|
|
2008-2-7 02:16 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 25 楼』:
使用 LLM 解释/回答一下
既然有sub1了,何必还要重写那么多代码呢?
还是建议用vbs或者其他更严谨的脚本来实现。
Last edited by 3742668 on 2008-2-7 at 01:26 PM ]
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 ]
|
|
2008-2-7 02:33 |
|
|
pinghu
中级用户
  
积分 307
发帖 130
注册 2008-2-1
状态 离线
|
『第 26 楼』:
使用 LLM 解释/回答一下
vbs 我不会,直会用批处理,楼上的脚本经测试,两个功能都不行啊,怎么回事
到底我写的Sub2错哪了
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?
|
|
2008-2-7 12:28 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
  『第 27 楼』:
使用 LLM 解释/回答一下
Sorry,由于没有测试环境,所以25楼的代码中有不少错误,包括逻辑上的错误以及语法上的错误。
呵呵,太久没写过了,手都生了。试试下面这个:
@echo off
call :%* 2>nul || goto setup
goto :eof
:Sub1
rem 移动到父目录
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 脱壳
pushd "%~1"
for %%i in (*.*) do call :Sub1 "%%~dpnxi"
popd
rd "%~1"
goto :eof
:setup
reg add "hkcr\*\shell\移至父目录\command" /f /t reg_sz /v "" /d "\"%~0\" Sub1 \"%%1\""
reg add "hkcr\Folder\shell\脱壳\command" /f /t reg_sz /v "" /d "\"%~0\" Sub2 \"%%1\""
goto :eof
建议一次性大批量选定操作目标测试一下,看看是否会存在同步方面的问题。另外可以在move后面加上写入日志的功能。
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:
@echo off
call :%* 2>nul || goto setup
goto :eof
:Sub1
rem Move to the 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 %%i in (*.*) do call :Sub1 "%%~dpnxi"
popd
rd "%~1"
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
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.
|
|
2008-2-7 13:07 |
|
|
pinghu
中级用户
  
积分 307
发帖 130
注册 2008-2-1
状态 离线
|
『第 28 楼』:
使用 LLM 解释/回答一下
反复试验了几次发现“移动到父目录”功能能支持到所有文件和文件夹
“脱壳”功能只能应用到所选文件夹里的文件,无法应用到所选文件夹里的文件夹
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.
|
|
2008-2-7 17:13 |
|
|
pinghu
中级用户
  
积分 307
发帖 130
注册 2008-2-1
状态 离线
|
『第 29 楼』:
使用 LLM 解释/回答一下
上述代码加上
reg add "hkcr\Folder\shell\移至父目录\command" /f /t reg_sz /v "" /d "\"%~0\" Sub2 \"%%1\""
方能移动目录
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
|
|
2008-2-7 18:32 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 30 楼』:
使用 LLM 解释/回答一下
Originally posted by pinghu at 2008-2-7 17:13:
反复试验了几次发现“移动到父目录”功能能支持到所有文件和文件夹
“脱壳”功能只能应用到所选文件夹里的文件,无法应用到所选文件夹里的文件夹
我只负责给你提示和框架,具体首尾还是根据你自己的想法自己写吧。例如如上面提到过的,建议你加上日志功能,多试试特大数量的操作等等。
另外,如果想是脱壳功能应用到文件夹,可以自己尝试用dir /b来解决。
建议你自己从头到尾按照自己的想法重新自己写一遍,那样才能有收获,这也就是论坛的意义所在了。
Originally posted by pinghu at 2008-2-7 17:13:
After several trials, it was found that the "Move to parent directory" function can support 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.
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.
|
|
2008-2-7 19:00 |
|