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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.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
windows迭代批处理文件返回错误中目录中的文件_Windows_Batch File_Cmd - Fatal编程技术网

windows迭代批处理文件返回错误中目录中的文件

windows迭代批处理文件返回错误中目录中的文件,windows,batch-file,cmd,Windows,Batch File,Cmd,我正在创建一个.bat文件,该文件通过特定目录中的文件进行迭代。这是代码中实现此功能的部分: @echo off setlocal ENABLEDELAYEDEXPANSION set DSPath=C:\Axway_DS set inFolder=!DSPath!\Datastore\getStarted\withDatastore\data set fileToTreat=!inFolder!\ set outFolder=C:\Users\acucu\Desktop\fold

我正在创建一个.bat文件,该文件通过特定目录中的文件进行迭代。这是代码中实现此功能的部分:

@echo off

 setlocal ENABLEDELAYEDEXPANSION

 set DSPath=C:\Axway_DS
 set inFolder=!DSPath!\Datastore\getStarted\withDatastore\data
 set fileToTreat=!inFolder!\
 set outFolder=C:\Users\acucu\Desktop\folders\exit\arn\out
 set DSRuntime=!DSPath!\Datastore\DatastoreRuntime
 set archive=C:\Users\acucu\Desktop\folders\exit\arn\archive

 set fileIn=deleteInput.txt
 set logSuppresion=supp.log
 set logMaintenance=maintenance.log
 set fichierTrace=!outFolder!\TRSUPIN.txt
 set case=SUPPRESSION

 for /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c%%a%%b)
 set mytime=%time%
 set mytime2=%time::=%
 set mytime2=%mytime2:.=%

cd !folderIn!
for %%i in (*) do ( 
echo Am intrat
set fileIn=%%i
set COUNTER=0
for /f "tokens=*" %%a in (!fileIn!) do (

set /A COUNTER+=1

  set countRows=0   
  set idInjection=%%a

      ......................

)
)

endlocal
问题出现在这里:

 C:\Users\acucu\Desktop\folders\exit\arn>cd !folderIn!
 The syntax of the command is incorrect.
执行就停止了。 我做错了什么? 现在,我在上次检查时运行的旧版本上遇到了相同的错误:

@echo off
setlocal ENABLEDELAYEDEXPANSION

set DSPath=C:\Axway_DS
set inFolder=!DSPath!\Datastore\getStarted\withDatastore\data
set fileToTreat=!inFolder!\
set outFolder=C:\Users\acucu\Desktop\folders\exit\arn\out
set DSRuntime=!DSPath!\Datastore\DatastoreRuntime
set archive=C:\Users\acucu\Desktop\folders\exit\arn\archive

set fileIn=deleteInput.txt
set logSuppresion=supp.log
set logMaintenance=maintenance.log
set fichierTrace=!outFolder!\TRSUPIN.txt
set case=SUPPRESSION

for /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c%%a%%b)
set mytime=%time%
set mytime2=%time::=%
set mytime2=%mytime2:.=%
set COUNTER=0

  for /f "tokens=*" %%a in (!fileIn!) do (

set /A COUNTER+=1

set countRows=0 
set idInjection=%%a

::Suppresion de l'injection
call !DSRuntime!\dstools deleteCollection -i %%a > !logSuppresion!_!COUNTER! 2>&1

IF !errorlevel!==0 (
    set result=OK 
    set comm= 
    ) ELSE (
     set result=KO
        for /f "delims=" %%x in (!logSuppresion!_!COUNTER!) do (
        set "comm=%%x"  )
        )


 call !DSRuntime!\dstools.bat maintenance -tasks CLEAN_COLLECTION > !logMaintenance!_!COUNTER!
    set /a count=0
    for /f "tokens=3 delims=:" %%i in ('find "Deleted row(s) count:" !logMaintenance!_!COUNTER!') do set /a count=%%i

    set countRows=!count!   


     ::Creation des dossiers s'ils n'existent pas
     if not exist !outFolder! mkdir !outFolder!
     if not exist %archive% mkdir %archive!%            

    ::Alimentation des variables avec des blancs  
    set countRows=!countRows!                  
    set fileIn=!fileIn!                                                                     
    set idInjection=!idInjection!                                                  
    set comm=!comm!                                                                                                    

    ::Creation du fichier de trace d'accompagnement
    if exist !fichierTrace! set            fichierTrace=!outFolder!\TRSUPIN_!mydate!_!mytime2!.txt 


    echo. 2>!fichierTrace!
    echo !case:~0,11!!countRows:~0,18!!fileIn:~0,50!!mydate!!mytime2:~0,-2!!idInjection:~0,50!!result!!comm:~0,100! > !fichierTrace!


    ::Copier les fichiers dans l'archive
    ::xcopy /q !fichierTrace! !archive!\%mydate%_%mytime2%\TRSUPIN.txt >nul
    ::xcopy /q !fileToInject! !archive!\%mydate%_%mytime2%\TRSUPIN.txt >nul

    ::Supprimer le fichier de log injection
    ::del !logMaintenance!_!COUNTER!
    ::del !logSuppresion!_!COUNTER!

   )
  endlocal

如果问题是
delayedExpansion
,请将其添加到命令之前

setlocal enableDelayedExpansion

如果
folderIn
中为空格,请在
cd
命令中的变量周围添加引号

cd "!folderIn!"

如果它是一个不完整的路径,请确保像这样完成它

cd "X:\Example\SubFolder\!folderIn!"

根据需要组合这些,或者让我们了解更多的见解

编辑
变量名不匹配? 试一试


三个问题:是否使用setlocal EnableDelayedExpansion,目录是否包含空格,是否在同一驱动器上。您确实需要在此处显示更多的代码,以便我们大致了解出错的原因。变量
folderIn
携带的值是什么?然后请包含更多代码,以及变量存储内容的示例。
folderIn
未定义
inFolder
是,但这是您的错误吗?不,不是。我想这可能与我的计算机有关,因为我有一个旧版本的脚本,没有几个小时前运行的循环,现在我有了相同的错误。我刚刚添加了另一个版本,我发现了问题所在。很明显,这是因为结尾的评论是:“。我现在正在使用rem,我没有任何错误。
cd "!inFolder!"