批次-开启名称不明的资料夹 [英] Batch - Open folder with unknown name
问题描述
所以我要访问此特定路径
So I want to access this specific path
c:\users\admin\social\profile\KoJumperz\pictures
但是我的朋友名字不是KoJumperz
,所以他的路径不一样.他的路会是
but my friends name isn't KoJumperz
so his path is not the same. His path would be
C:\users\admin\social\profile\JhonSmith\pictures
有没有一种方法可以创建将打开我的个人资料文件夹中第一个文件夹的代码?
Is there a way to create a code that will open the first folder in my profile folder?
推荐答案
-
开始枚举文件夹,并在第一次迭代后中断循环:
Start enumerating the folders and break the loop after the first iteration:
for /d %%d in (C:\users\admin\social\profile\*) do (set profile=%%d & goto break)
:break
echo Using %profile%\pictures
要获取第二个文件夹,请跳过目录列表的1个条目:
To get the 2nd folder skip 1 entry of dir listing:
for /f "skip=1 delims=" %%d in ('dir /b /a:d "C:\users\admin\social\profile\*"') do (
set profile=%%d
goto break
)
:break
使用skip=2
获得第三名,依此类推.
Use skip=2
to get the 3rd and so on.
或查找可以在用户PC上设置的环境变量,例如%socialusername%
(确切的变量名称可以通过在命令提示符控制台中运行set
来查看):
Or find an environment variable that may be set on the user's PC, for example %socialusername%
(the exact variable name can be seen by running set
in command prompt console):
echo Using C:\users\admin\social\profile\%socialusername%\pictures
这篇关于批次-开启名称不明的资料夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!