0

我有这样的结构

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”,然后在集成服务中部署文件夹为 Y -File1 和File2 在文件夹“M”File3 和 File 4 中。即。

------------------Folder y-----------
      --File1.
      --File2
------------------Folder m-----------
      --File3.
      --File4----

--依此类推,即祖父文件夹名称不同 --父文件夹一致 --取决于suto子文件夹下的大文件夹名称存在。我需要遍历大文件夹并获取 .dtsx 文件,我需要将它们部署在集成服务中,文件夹名称为大文件夹名称。

4

2 回答 2

2

干得好delayed expansion

@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
于 2013-07-03T07:11:36.637 回答
2
@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_name"应包含格式的行

"file3.dtsx" "m"

该文件"%temp%\tempfile_anothername"应包含这些行,并按文件名的字母顺序进行排序。

不确定是否需要引号、需要的元素顺序、需要的输出顺序,或者您是否还需要"z"目录(它可以作为%%~nm


附录以下评论 20130703-1355Z

天啊!混乱开始!

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

... ,D:\Folder 1\SubFolder1\SubFolder2_SubFolder3\SubFolder4\Entity\Folder\File1_1.dtsx ;

... D:\Data Migration\DX\AE_Deployment_SAT\20-Interfaces\Flex Att Per

然而,其中第二个并未出现在当前可用的评论中。

这是我用来创建当前评论中报告的文件的批次-我所做的只是编辑驱动器号-我什至将其保留Entity为张贴而不是Entity1叙述:

@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

运行我原来贴的批处理"%%~nm"ECHO行了,有修正

...
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"

所以 - 对我有用。不知道您实际想要生产什么,不幸的是您似乎正在审查结果。我只能使用您提供的数据... :(

于 2013-07-03T06:32:35.550 回答