Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 批处理文件脚本-通过文件夹迭代并部署包_Batch File - Fatal编程技术网

Batch file 批处理文件脚本-通过文件夹迭代并部署包

Batch file 批处理文件脚本-通过文件夹迭代并部署包,batch-file,Batch File,我的结构像 E:\X\Y\z\File1.dtsx E:\X\Y\z\File2.dtsx E:\X\M\z\File3.dtsx E:\X\M\z\File4.dtsx... 我想遍历包含.dtsx文件的文件夹,并获取其祖父母文件夹名[I,e]。在这种情况下,我需要获取“Y”和“M”,然后在Integration services中部署,其中文件夹为Y-File1和File2,其中文件夹为“M”File3和file4。 即 --等等 i、 e祖父母文件夹名称不同--父文件夹一致--取决于su

我的结构像

E:\X\Y\z\File1.dtsx
E:\X\Y\z\File2.dtsx
E:\X\M\z\File3.dtsx
E:\X\M\z\File4.dtsx...
我想遍历包含.dtsx文件的文件夹,并获取其祖父母文件夹名[I,e]。在这种情况下,我需要获取“Y”和“M”,然后在Integration services中部署,其中文件夹为Y-File1和File2,其中文件夹为“M”File3和file4。 即

--等等 i、 e祖父母文件夹名称不同--父文件夹一致--取决于suto子文件夹包下的主文件夹名称。我需要遍历grandfolder并获取.dtsx文件,我需要将它们部署在集成服务中,文件夹名为grandfolder name

@ECHO OFF
SETLOCAL
:: starting directory
SET "relroot=u:"
(
FOR /f "delims=" %%i IN ( 'dir /s /b /a-d "%relroot%\*.dtsx" ') DO (
 FOR /f "delims=" %%m IN ("%%~dpi.") DO (
  FOR /f "delims=" %%q IN ("%%~dpm.") DO (
   ECHO "%%~nxi" "%%~nq"
  )
 )
)
)>"%temp%\tempfile_name"
SORT "%temp%\tempfile_name" >"%temp%\tempfile_anothername"
GOTO :EOF
这是开胃菜

文件
“%temp%\tempfile\u name”
应包含以下格式的行

"file3.dtsx" "m"
文件
“%temp%\tempfile\u anothername”
应包含这些行,并按文件名的字母顺序排序

不确定是否需要引号、所需元素的顺序、所需输出的顺序,或者是否还需要
“z”
目录(可通过
%%~nm
获得)


注释后的附录20130703-1355Z

哦,天哪!混乱区域

Stackexchange的定期收件箱通知包括一小部分已发布的评论,并在两份连续报告中阅读:

,D:\Folder 1\SubFolder1\SubFolder2\u SubFolder3\SubFolder4\Entity\Folder\File1\u 1.dtsx

。。。D:\Data Migration\DX\AE\U Deployment\U SAT\20接口\Flex Att Per

然而,第二个问题没有出现在当前可用的评论中

下面是我用来创建当前评论中报告的文件的批处理—我所做的只是编辑驱动器号—我甚至将
实体
保留为已发布,而不是如所述的
实体1

@echo off
setlocal
del /s u:\*.dtsx
md "U:\Folder 1\SubFolder1\SubFolder2_SubFolder3\SubFolder4\Entity\Folder" 2>nul
md "U:\Folder 1\SubFolder1\SubFolder2_SubFolder3\SubFolder4\Entity1\Folder" 2>nul
md "U:\Folder 1\SubFolder1\SubFolder2_SubFolder3\SubFolder4\Entity2\Folder" 2>nul
copy nul "U:\Folder 1\SubFolder1\SubFolder2_SubFolder3\SubFolder4\Entity\Folder\File1_1.dtsx
copy nul "U:\Folder 1\SubFolder1\SubFolder2_SubFolder3\SubFolder4\Entity1\Folder\File1_2.dtsx"
copy nul "U:\Folder 1\SubFolder1\SubFolder2_SubFolder3\SubFolder4\Entity2\Folder\File1_3.dtsx"
copy nul "U:\Folder 1\SubFolder1\SubFolder2_SubFolder3\SubFolder4\Entity2\Folder\File1_4.dtsx"
dir/s u:\*.dtsx
结果:

u:\Folder 1\SubFolder1\SubFolder2_SubFolder3\SubFolder4\Entity\Folder\File1_1.dtsx
u:\Folder 1\SubFolder1\SubFolder2_SubFolder3\SubFolder4\Entity1\Folder\File1_2.dtsx
u:\Folder 1\SubFolder1\SubFolder2_SubFolder3\SubFolder4\Entity2\Folder\File1_3.dtsx
u:\Folder 1\SubFolder1\SubFolder2_SubFolder3\SubFolder4\Entity2\Folder\File1_4.dtsx
运行我最初发布的批,在
ECHO
行添加
“%%~nm”
,并进行修改

...
SORT "%temp%\tempfile_name" >"%temp%\tempfile_anothername"
type "%temp%\tempfile_name" 
echo================================
TYPE "%temp%\tempfile_anothername"
GOTO :EOF
结果如下:

"File1_1.dtsx" "Entity" "Folder"
"File1_2.dtsx" "Entity1" "Folder"
"File1_3.dtsx" "Entity2" "Folder"
"File1_4.dtsx" "Entity2" "Folder"
===============================
"File1_1.dtsx" "Entity" "Folder"
"File1_2.dtsx" "Entity1" "Folder"
"File1_3.dtsx" "Entity2" "Folder"
"File1_4.dtsx" "Entity2" "Folder"
所以-对我有用。不知道你到底想要生产什么,不幸的是你似乎在审查结果。我只能使用您提供的数据…:(

这是开胃菜

文件
“%temp%\tempfile\u name”
应包含以下格式的行

"file3.dtsx" "m"
文件
“%temp%\tempfile\u anothername”
应包含这些行,并按文件名的字母顺序排序

不确定是否需要引号、所需元素的顺序、所需输出的顺序,或者是否还需要
“z”
目录(可通过
%%~nm
获得)


注释后的附录20130703-1355Z

哦,天哪!混乱区

Stackexchange的定期收件箱通知包括一小部分已发布的评论,并在两份连续报告中阅读:

…,D:\Folder 1\SubFolder1\SubFolder2\u SubFolder3\SubFolder4\Entity\Folder\File1\u 1.dtsx

…D:\Data Migration\DX\AE\U Deployment\U SAT\20接口\Flex Att Per

然而,第二个问题没有出现在当前可用的评论中

下面是我用来创建当前评论中报告的文件的批处理—我所做的只是编辑驱动器号—我甚至将
实体
保留为已发布,而不是如所述的
实体1

@echo off
setlocal
del /s u:\*.dtsx
md "U:\Folder 1\SubFolder1\SubFolder2_SubFolder3\SubFolder4\Entity\Folder" 2>nul
md "U:\Folder 1\SubFolder1\SubFolder2_SubFolder3\SubFolder4\Entity1\Folder" 2>nul
md "U:\Folder 1\SubFolder1\SubFolder2_SubFolder3\SubFolder4\Entity2\Folder" 2>nul
copy nul "U:\Folder 1\SubFolder1\SubFolder2_SubFolder3\SubFolder4\Entity\Folder\File1_1.dtsx
copy nul "U:\Folder 1\SubFolder1\SubFolder2_SubFolder3\SubFolder4\Entity1\Folder\File1_2.dtsx"
copy nul "U:\Folder 1\SubFolder1\SubFolder2_SubFolder3\SubFolder4\Entity2\Folder\File1_3.dtsx"
copy nul "U:\Folder 1\SubFolder1\SubFolder2_SubFolder3\SubFolder4\Entity2\Folder\File1_4.dtsx"
dir/s u:\*.dtsx
结果:

u:\Folder 1\SubFolder1\SubFolder2_SubFolder3\SubFolder4\Entity\Folder\File1_1.dtsx
u:\Folder 1\SubFolder1\SubFolder2_SubFolder3\SubFolder4\Entity1\Folder\File1_2.dtsx
u:\Folder 1\SubFolder1\SubFolder2_SubFolder3\SubFolder4\Entity2\Folder\File1_3.dtsx
u:\Folder 1\SubFolder1\SubFolder2_SubFolder3\SubFolder4\Entity2\Folder\File1_4.dtsx
运行我最初发布的批,在
ECHO
行添加
“%%~nm”
,并进行修改

...
SORT "%temp%\tempfile_name" >"%temp%\tempfile_anothername"
type "%temp%\tempfile_name" 
echo================================
TYPE "%temp%\tempfile_anothername"
GOTO :EOF
结果如下:

"File1_1.dtsx" "Entity" "Folder"
"File1_2.dtsx" "Entity1" "Folder"
"File1_3.dtsx" "Entity2" "Folder"
"File1_4.dtsx" "Entity2" "Folder"
===============================
"File1_1.dtsx" "Entity" "Folder"
"File1_2.dtsx" "Entity1" "Folder"
"File1_3.dtsx" "Entity2" "Folder"
"File1_4.dtsx" "Entity2" "Folder"

所以-对我来说很有效。不知道你到底想要生产什么,不幸的是你似乎在审查结果。我只能处理你提供的数据…:(

延迟扩展做得好:

@echo OFF &SETLOCAL
SET LF=^


REM do not touch two empty lines
FOR /R "E:\X" %%a IN (*.dtsx) DO call:doit "%%~a"
goto:eof

:doit
SET "fpath=%~1"
SETLOCAL ENABLEDELAYEDEXPANSION
SET fpath=%fpath:\="!LF!"%
FOR %%b IN ("%fpath%") DO (
    SET "path2=!path1!"
    SET "path1=!fname!"
    SET "fname=%%~b"
)
ECHO file is "%fname%", father is "%path1%", grandfather is "%path2%".
ENDLOCAL
goto:eof

延迟扩展的工作做得很好:

@echo OFF &SETLOCAL
SET LF=^


REM do not touch two empty lines
FOR /R "E:\X" %%a IN (*.dtsx) DO call:doit "%%~a"
goto:eof

:doit
SET "fpath=%~1"
SETLOCAL ENABLEDELAYEDEXPANSION
SET fpath=%fpath:\="!LF!"%
FOR %%b IN ("%fpath%") DO (
    SET "path2=!path1!"
    SET "path1=!fname!"
    SET "fname=%%~b"
)
ECHO file is "%fname%", father is "%path1%", grandfather is "%path2%".
ENDLOCAL
goto:eof

我已经修复了(我希望)一些格式问题——我不是唯一一个尝试的人。也遗漏了一些问题——不确定“suto”是否应该是“auto”,但我看不出这会有什么帮助:(.不过,对于用一种不熟悉的语言进行的勇敢尝试,我没有批评。我在你的语言中做得也不好……只是不确定需要什么,但我会给它一个震动……我已经修好了(我希望)一些格式问题-我不是唯一一个尝试的人。也遗漏了一些-不确定“suto”是否应该是“auto”,但我看不出这会有什么帮助:(.尽管如此,对于用一种不熟悉的语言进行的勇敢尝试,我没有批评。我在你的语言中做得也不好…只是不确定需要什么,但我会让它震动一下…嗨,彼得,上面的解决方案是显示空的scrennYes-输出在文件
%temp%\tempfile\u name“
%temp%\tempfile\u其他名称”中
。您需要
键入它们来显示结果。您还需要将
relroot
更改为
E:
-我在
u:
驱动器上设置了一些文件进行测试。嗨,彼得,d:\Folder 1\SubFolder1\SubFolder2\u SubFolder3\SubFolder4\Entity1\File1\u 1.dtsxHi彼得,d:\Folder 1\subfolder 2\u SubFolder3\SubFolder4\实体\Folder\File1\u 1.dtsx;D:\Folder 1\SubFolder1\SubFolder2\u SubFolder3\SubFolder4\Entity1\Folder\File1\u 2.dtsx;D:\Folder 1\SubFolder1\SubFolder2\u SubFolder3\SubFolder4\Entity2\Folder\File1\u 3.dtsx;D:\Folder 1\subfolderfolder1\SubFolder2\u SubFolder3\SubFolder4\Entity2\Folder\File1\u 4.dtsx;o/p显示File1\u 1,File1\u 2 entity1但File1\u 3,File1\u 4显示子文件夹4它应该显示Entity2Hi-peter,上面的解决方案显示空的scrennYes-输出在文件
%temp%\tempfile\u name”
%temp%\tempfile\u另一个名称中
。您需要
键入它们来显示结果。您还需要将
relroot
更改为
E:
-我在
u:
驱动器上设置了一些文件进行测试。嗨,彼得,d:\Folder 1\SubFolder1\SubFolder2\u SubFolder3\SubFolder4\Ent