下一个、上一个并行文件夹
我正在尝试使用批处理文件和程序创建一个相对快捷方式,以使用图标在 exe 程序中转换批处理。
我需要一个“快捷方式”来在资源管理器窗口中打开下一个字母并行文件夹,并需要一个“快捷方式”来打开上一个。理想情况下,我什至希望它关闭用于双击它的资源管理器窗口。
到目前为止,我已经:
@echo off
echo %cd%
for %%a in ("%cd%") do set folder=%%~na
pushd ..
echo %folder%
echo .
dir /A:D /B
pause
%folder%具有执行批处理的文件夹的名称(不是路径!)。
该行: dir /A:D /B 为您提供多行输出,为您提供所有并行文件夹(因为我使用 Pushd 提升了一个级别..)。我真的需要找到一种方法来搜索 %fodler% 值并选择它上方或下方的行。
我尝试使用 for /f 进行一些操作,但在处理多行而不是单个字符串时,它并没有那么有用。
有什么想法吗?
I am trying to make a relative shortcut using a batchfile and a program to turn the batch in an exe program with an icon.
I need a 'shortcut' to open the next alfabetic parallel folder in an explorer window and one to open the previous. Ideally I would even like it to to close the explorer window used to doubleclick it.
I have so far:
@echo off
echo %cd%
for %%a in ("%cd%") do set folder=%%~na
pushd ..
echo %folder%
echo .
dir /A:D /B
pause
the %folder% has the name of the folder (not path!) from where the batch is executed.
the line: dir /A:D /B gives you an output of multiple lines giving you all the parallel folders (because I go up a level using pushd ..). I really need to find a way to search for the %fodler% value and pick the line above, or below it.
I tried something using for /f but it is not that usefull when processing multiple lines instead of one single string.
anny ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尽管我不太清楚您到底想要实现什么,但以下代码片段应该可以满足您的要求。只需将其添加到您的脚本中即可:
说明:
3 个变量
previous
、current
和next
的使用方式类似于轮班登记。在每次循环迭代中,当前目录值通过变量移动一位在移动结束时,将测试当前变量是否为所需的文件夹
如果循环在条件为真之前结束,这意味着最后一个文件夹是正确的,因此尾随移动。
希望有帮助...
Even though it is not quite clear to me what exactly you want to achieve, the following snippet should do what you want. Simply add it to your script:
Explanation:
The 3 variables
previous
,current
andnext
are use like a shift register. In each loop iteration the current directory value is shifted by one place through the variablesAt the end of the shifting the
current
variable is tested for the desired folderIf the loop ends before the condition is true, this means the last folder is the correct one, hence that trailing shifts.
Hope that helps...