批量For循环..通配符来确定搜索到的文件长度? [英] Batch For loop.. wildcards to determine length of searched files?
问题描述
我被困在一张code的,我主要是没写我自己。我在寻找通过与延长的.dwg的所有文件运行code,以及K_E启动,并有长9本能地我用通配符,但不起作用。
K_E ??????。DWG会做的伎俩在我head..but没有。
我需要这个长度,原因是在更深的文件夹中有
K_E ?????? xx.dwg和其他文件。
在子文件夹中的其他文件可以有各种其他的名字,一般的想法是,我只想被命名完全相同的文件K_E [插入6numbershere]的.dwg要么,或文件夹深度的限制= 2。我也试图在文件夹名称通配符允许code到只有2 K_E *图纸文件夹深的样子,但也没有工作。像C:\\用户\\ b00m49 \\桌面\\ LSPTEST ** \\ K_E *的.dwg也工作..
在code被认为能打开图纸,申请一个脚本,并移动到下一个文件。
这是我迄今的工作。
为/ RC:\\用户\\ b00m49 \\桌面\\ LSPTEST%%一中(K_E * .DWG)做(启动/等待C:\\ Program Files文件\\欧特克\\ AutoCAD的2013 \\的acad.exe%%一个/ bC:\\用户\\ b00m49 \\桌面\\ LSPTEST \\ expSQM.scr)
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SETsourcedir = C:\\用户\\ b00m49 \\桌面\\ LSPTEST
SETsourcedir = U:\\ sourcedir
用于/ R%sourcedir%%%一中(K_E * .DWG)做(
FOR / F令牌= 1,6delims = \\%%米(%% A)DO(
REM %% n和目录名含有或文件名或空
REM %% n是只为0,1或2级击落空。
IF%% N==(
SETNAME = %%〜娜
IF名称:!〜9==如果的名字!〜8! NEQ(
REM的名字不超过9个字符长,但比8再
ECHO(启动/等待C:\\ Program Files文件\\欧特克\\ AutoCAD的2013 \\的acad.exe%%一个/ BC:\\用户\\ b00m49 \\桌面\\ LSPTEST \\ expSQM.scr)
)
)
)
)
GOTO:EOF
您将需要更改 sourcedir
的设置,以适应您的情况。我用了一个测试目录。
所需的启动命令仅仅是为了测试目的 ECHO
编辑。 您已经验证后,该命令是正确,将 ECHO(START
到开始
真正开始的进程。
我不知道你的意思是什么两个层次下 - 我假定目标目录+两个层次。由于您的实际dirctory有3个比我test目录多层次,你可能需要修改 1,6
到 1.9
只需使用tokenising功能,以确保有不超过?目录中,其中的DRIVENAME和文件名算作级别的水平。忽略该文件是否存在。
然后得到的名字 - 我们知道第3个字符 K_E
但是,我们确切地后6个字符的希望,所以看是否有字符10+,如果有不,确保字符9存在(字符从0数),如果这两个条件是有效的,那么它必须是K_E * 6characters *
能保证,如果所需的所有6个字符是数字,但实际上没有指定。
BTW - 添加信息,请编辑它变成你的问题使人们不必追遍线程
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SETsourcedir = U:\\用户\\ b00m49 \\桌面\\ LSPTEST
用于/ R%sourcedir%%%一中(K_E * .DWG)做(
FOR / F令牌= 1,9delims = \\%%米(%% A)DO(
REM %% n和目录名含有或文件名或空
REM %% n是只为0,1或2级击落空。
IF%% N==(
SETNAME = %%〜娜
IF名称:!〜9==如果的名字!〜8! NEQ(
REM的名字不超过9个字符长,但比8再
ECHO(启动/等待C:\\ Program Files文件\\欧特克\\ AutoCAD的2013 \\的acad.exe%%一个/ BC:\\用户\\ b00m49 \\桌面\\ LSPTEST \\ expSQM.scr)
)
)
)
)
暂停
GOTO:EOF
这为我工作。
注:
的暂停
行应停止手术后要执行它的显示的命令。
您需要 U的改变:
到 C:
中的设置 sourcedir
来把它处理你的 C:
驱动器
您将需要更改 ECHO(启动
到启动
,以实际执行 AutoCAD的
处理。这种技术(回声
ING命令)用于显示命令才能拥有它验证。注意,我还特意插入一对rabbit's-耳(,
),因为第一个报价参数启动
被作为窗口标题。
I'm stuck on a piece of code that I mainly didn't write myself. I'm looking for a code that runs through all files with extension .dwg, and start with K_E , and have length 9. instinctively I used wildcards, but that doesn't work..
K_E??????.dwg would do the trick in my head..but doesn't.
the reason I need this length, is that in deeper folders there are K_E??????xx.dwg and other files.
The other files in subfolders can have a range of other names, the general idea is that I only want files that are exactly named K_E[insert 6numbershere].dwg Either that, or the limit of folders depth = 2. I also tried the wildcard in the folder names to allow the code to look in only 2 deep folders for K_E*.dwg files, but that also didn't work. something like C:\Users\b00m49\Desktop\LSPTEST**\K_E*.dwg could also work..
the code is supposed to open the drawings, apply a script, and move on to the next file.
this is what I'm working with so far.
for /r "C:\Users\b00m49\Desktop\LSPTEST" %%a in (K_E*.dwg) do ( start /wait "C:\Program Files\Autodesk\Autocad 2013\acad.exe" "%%a" /b "C:\Users\b00m49\Desktop\LSPTEST\expSQM.scr")
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "sourcedir=C:\Users\b00m49\Desktop\LSPTEST"
SET "sourcedir=U:\sourcedir"
for /r "%sourcedir%" %%a in (K_E*.dwg) do (
FOR /f "tokens=1,6delims=\" %%m IN ("%%a") DO (
REM %%n contain dirname or filename or empty
REM %%n is only empty for 0, 1 or 2 levels down.
IF "%%n"=="" (
SET "name=%%~na"
IF "!name:~9!"=="" IF "!name:~8!" neq "" (
REM the name is not longer than 9 characters, but IS longer than 8
ECHO(start /wait "C:\Program Files\Autodesk\Autocad 2013\acad.exe" "%%a" /b "C:\Users\b00m49\Desktop\LSPTEST\expSQM.scr")
)
)
)
)
GOTO :EOF
You would need to change the setting of sourcedir
to suit your circumstances. I used a test directory.
The required START commands are merely ECHO
ed for testing purposes. After you've verified that the commands are correct, change ECHO(START
to START
to actually start the processes.
I'm not sure what you mean by "two levels down" - I've assumed the target directory +two levels. Since your actual dirctory has 3 more levels than my test directory, you'd probably need to change 1,6
to 1,9
Simply use the tokenising feature to ensure that there are no more than ? levels of directory, where the drivename and filename count as levels. Ignore the file if there are.
Then get the name - we know the first 3 characters are K_E
but we want exactly 6 characters after, so see whether there are characters 10+ and if there are not, make sure character 9 exists (characters count from 0) and if both of these conditions are valid then it must be K_E*6characters*
Could ensure that all 6 characters are numeric if required, but not actually specified.
BTW - to add information, please edit it into your question so people don't need to chase all over the thread.
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "sourcedir=U:\Users\b00m49\Desktop\LSPTEST"
for /r "%sourcedir%" %%a in (K_E*.dwg) do (
FOR /f "tokens=1,9delims=\" %%m IN ("%%a") DO (
REM %%n contain dirname or filename or empty
REM %%n is only empty for 0, 1 or 2 levels down.
IF "%%n"=="" (
SET "name=%%~na"
IF "!name:~9!"=="" IF "!name:~8!" neq "" (
REM the name is not longer than 9 characters, but IS longer than 8
ECHO(start /wait "" "C:\Program Files\Autodesk\Autocad 2013\acad.exe" "%%a" /b "C:\Users\b00m49\Desktop\LSPTEST\expSQM.scr")
)
)
)
)
pause
GOTO :EOF
This worked for me.
Notes:
The pause
line should stop the procedure after it displays the command to be executed.
You would need to change U:
to C:
in the setting of sourcedir
to have it process your c:
drive.
You would need to change ECHO(start
to start
in order to actually execute the autocad
processing. This technique (echo
ing the command) is used to show the command in order to have it verified. Note I've also deliberately inserted a pair of rabbit's-ears (""
) because the first quoted argument to start
is taken as the window-title.
这篇关于批量For循环..通配符来确定搜索到的文件长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!