Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/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
Loops 批处理文件以循环遍历文件夹中的每个文件_Loops_Batch File - Fatal编程技术网

Loops 批处理文件以循环遍历文件夹中的每个文件

Loops 批处理文件以循环遍历文件夹中的每个文件,loops,batch-file,Loops,Batch File,我已经创建了一个脚本,希望它在目录中的所有文件中循环。。 但我没能做到。。 我创建了另一个脚本来应用脚本(更改内容)。。 这里是代码 cd \input for %%f in (*.txt) do ( echo "%%~nf" "D:\deployment code\change_content" .\"%%~nf".txt ) change_content.bat call :yesterday today -1 for /f "d

我已经创建了一个脚本,希望它在目录中的所有文件中循环。。 但我没能做到。。 我创建了另一个脚本来应用脚本(更改内容)。。 这里是代码

cd \input

for %%f in (*.txt) do (

            echo "%%~nf"
            "D:\deployment code\change_content" .\"%%~nf".txt
    )
change_content.bat

call :yesterday today -1
for /f "delims=" %%a in (%1) do (
set "val=%%a"
if "!val:~12,10!"=="0001-01-01" (
>> D:\temp\%1_changed.txt echo !val:~0,12!%day%!val:~22!
) else (
>> D:\temp\%1_changed.txtecho %%a     
)
)
我的问题是,如果将输入文件作为变量,我无法让脚本读取该文件。我只能放入实际文件,这对自动化流程没有帮助? 这只是我指向输入和输出方向的代码的一部分。。 我只是想知道我该怎么办


如果有人能在这方面提供帮助,我将不胜感激。。谢谢:)

我理解您的问题,正如您在上面粗体文本中列出的那样。下面的内容应该可以从内存中使用,但我现在无法测试它,因为我现在没有Windows电脑(很高兴我不必随身携带)

如果在主程序循环部分安装,请尝试以下操作:

setlocal eneabledelayedexpansion

REM:: take \input as param from command line
set top_folder=%~1
set change_content="D:\deployment code\change_content.bat"

for /f "eol=; tokens=1 delims=" %%t in ( 'dir /b !top_folder!\*.txt' ) do (
  REM:: the /b may or may not give yo the full path you need
  REM:: google this if I am wrong

  set file_name=%%~nt
  !change_content! !file_name!

)
setlocal enabledelayedexpansion

REM:: change_content looping over file_name variable.
set file_name=%~1
for /f "eol=; tokens=1 delims=" %%f in ( 'type "!file_name!"' ) do (
  set line=%%f
  REM::  Do your thang in here with !line!.
) 
如果您对更改内容部分感兴趣,请尝试以下操作:

setlocal eneabledelayedexpansion

REM:: take \input as param from command line
set top_folder=%~1
set change_content="D:\deployment code\change_content.bat"

for /f "eol=; tokens=1 delims=" %%t in ( 'dir /b !top_folder!\*.txt' ) do (
  REM:: the /b may or may not give yo the full path you need
  REM:: google this if I am wrong

  set file_name=%%~nt
  !change_content! !file_name!

)
setlocal enabledelayedexpansion

REM:: change_content looping over file_name variable.
set file_name=%~1
for /f "eol=; tokens=1 delims=" %%f in ( 'type "!file_name!"' ) do (
  set line=%%f
  REM::  Do your thang in here with !line!.
) 

安装Cygwin。使用bash。你会更开心的…让我知道我在你最后一次评论后添加的内容是否没有必要,我可以回复你接受时的答案。(直到提交最后一次编辑后,我才看到接受)。谢谢:)嗯。。事实上,我可以和类型一起工作!文件名!其余的我都没试过。。不管怎样,仍然可以正常工作:)