下一个、上一个并行文件夹

发布于 2024-09-13 08:11:25 字数 511 浏览 5 评论 0原文

我正在尝试使用批处理文件和程序创建一个相对快捷方式,以使用图标在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

于我来说 2024-09-20 08:11:25

尽管我不太清楚您到底想要实现什么,但以下代码片段应该可以满足您的要求。只需将其添加到您的脚本中即可:

setlocal enabledelayedexpansion

for /f %%a in ('dir /b /ad /on') do (

   @rem shift the current value through the variables
   set previous=!current!
   set current=!next!
   set next=%%a

   @rem check if the "current" value is the right one
   if "!current!"=="%folder%" goto :found
)

@rem if we get here the loop has finished without %current% having the expected value
@rem but we need to check if it was the last folder in the directory
if "%next%"=="%folder%" (
    set previous=%current%
    set current=%next%
    set next=
    goto :found
)

endlocal

@rem exit here if no match is found (should never happen)
goto :eof

@rem variables should have valid values
:found
echo %previous%
echo %current%
echo %next%

说明:

3 个变量 previouscurrentnext 的使用方式类似于轮班登记。在每次循环迭代中,当前目录值通过变量移动一位

在移动结束时,将测试当前变量是否为所需的文件夹

如果循环在条件为真之前结束,这意味着最后一个文件夹是正确的,因此尾随移动。

希望有帮助...

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:

setlocal enabledelayedexpansion

for /f %%a in ('dir /b /ad /on') do (

   @rem shift the current value through the variables
   set previous=!current!
   set current=!next!
   set next=%%a

   @rem check if the "current" value is the right one
   if "!current!"=="%folder%" goto :found
)

@rem if we get here the loop has finished without %current% having the expected value
@rem but we need to check if it was the last folder in the directory
if "%next%"=="%folder%" (
    set previous=%current%
    set current=%next%
    set next=
    goto :found
)

endlocal

@rem exit here if no match is found (should never happen)
goto :eof

@rem variables should have valid values
:found
echo %previous%
echo %current%
echo %next%

Explanation:

The 3 variables previous, current and next are use like a shift register. In each loop iteration the current directory value is shifted by one place through the variables

At the end of the shifting the current variable is tested for the desired folder

If the loop ends before the condition is true, this means the last folder is the correct one, hence that trailing shifts.

Hope that helps...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文