首页 \ 问答 \ 使用Windows批处理脚本在文件夹中的多个文件中查找和替换字符串(Find and replace string in multiple files within a folder using windows Batch script)

使用Windows批处理脚本在文件夹中的多个文件中查找和替换字符串(Find and replace string in multiple files within a folder using windows Batch script)

我正在尝试编写批处理文件来查找和替换文件夹中多个文件中的字符串。 但是我收到了这个错误:

无法执行循环复制

知道为什么会这样吗?

@echo off
SETLOCAL
for %%* in (.) do set foldername=%%~n*
SET stringtofindreplace=XXXX
for %%f in (*.fmw) do (
    echo Processing %%f...
    fOR /F "delims=" %%l IN (%%f) DO (
         SET "line=%%l"
         SETLOCAL ENABLEDELAYEDEXPANSION 
         set "x=!line:%stringtofindreplace%=%foldername%!" 
         echo(!x!
         ENDLOCAL)
    )>%%~nf.new
)
GOTO:EOF

I am trying to write a batch file to find and replace a string in multiple files within a folder. But I am getting this error:

Cannot perform a cyclic copy

Any idea why that happens?

@echo off
SETLOCAL
for %%* in (.) do set foldername=%%~n*
SET stringtofindreplace=XXXX
for %%f in (*.fmw) do (
    echo Processing %%f...
    fOR /F "delims=" %%l IN (%%f) DO (
         SET "line=%%l"
         SETLOCAL ENABLEDELAYEDEXPANSION 
         set "x=!line:%stringtofindreplace%=%foldername%!" 
         echo(!x!
         ENDLOCAL)
    )>%%~nf.new
)
GOTO:EOF

原文:https://stackoverflow.com/questions/22234650
更新时间:2023-11-02 09:11

最满意答案

第一个实例化可能会成功,因为它从编辑器中克隆了预制件,但是随后您将新克隆的预制件重新分配给了enemyFormation 。 当所有敌人(儿童)被摧毁时(假设你正在使用Destroy() ),那么enemyFormation将不包含任何孩子。 下次你Instantiate(enemyFormation)你应该得到一个没有孩子的游戏对象,因为它不再是编辑器的预制件(它被你重新分配)。

对不起,我必须删除以前的答案。 反正这是错的。


The first instantiation may be successful because it cloned the prefab from the Editor but then you reassigned the newly cloned prefab to the enemyFormation. When all enemies (children) were destroyed (assume that you were using Destroy()) then enemyFormation would contain no child. Next time you Instantiate(enemyFormation) you were expected to get a gameObject without children because it were not the prefab from the Editor anymore (it was reassigned by you).

Sorry I have to delete the previous answer. It is wrong anyway.

相关问答

更多
  • 如果您尝试重新启动场景,则可以显示相同的场景并重置为默认值: let scene = GameScene(size: self.size) // Whichever scene you want to restart (and are in) let animation = SKTransition.crossFade(withDuration: 0.5) // ...Add transition if you like self.view?.presentScene(scene, transition: ...
  • 问题是您正在尝试在访问它们时删除for循环中的Object。 这是你应该做的: 1 .Find所有Child对象并将它们存储在一个数组中 2.在另一个循环中销毁它们 public void ClearChildren() { Debug.Log(transform.childCount); int i = 0; //Array to hold all child obj GameObject[] allChildren = new GameObject[transform. ...
  • 您可以使用几行代码从任何Visual元素创建一个图像(几乎所有控件都扩展Visual类)。 而不是再次重复自己,请参阅我如何截取WPF控件截图的答案? 问题,找出如何做到这一点。 现在您需要做的就是重新排列XAML,以便将所有行控件放在一个控件中 。 因此,我建议您定义一个新的Grid控件,在相关的Grid行中需要很多列...您可以使用Grid.IsSharedSizeScope附加属性将新的Grid列与任何外部列对齐(如果需要)。 最后,只需将对新Grid的引用传递给链接问题的代码,您将获得控件的Imag ...
  • 首先,“主要表现”是相对的。 如果这是你唯一的精灵,你将看不到sprite批处理它们的任何效果。 如果您同时在屏幕上显示数十个故事,那就不同了。 您无法同时向两个父节点添加节点。 你可以做的是创建一个“容器”精灵。 创建一个带有纹理的CCSprite(与sprite批处理节点纹理相同)和一个CGRectEmpty作为纹理rect。 这使精灵不会绘制任何东西,你可以使用它,就好像它是一个添加到CCSpriteBatchNode的CCNode。 然后你可以将你的精灵添加到那个不可见的精灵中,并使用容器精灵来影响 ...
  • StackPanel和Grid都从Panel继承,因此您可以将方法更改为: public UIElementCollection retCol (Panel givenObject){ return givenObject.Children; } 或者如果你想让它可用于所有UIElement类型,你可以使它更通用并检查函数中的类型: public UIElementCollection retCol (UIElement givenObject){ if(givenObject is Pa ...
  • 第一个实例化可能会成功,因为它从编辑器中克隆了预制件,但是随后您将新克隆的预制件重新分配给了enemyFormation 。 当所有敌人(儿童)被摧毁时(假设你正在使用Destroy() ),那么enemyFormation将不包含任何孩子。 下次你Instantiate(enemyFormation)你应该得到一个没有孩子的游戏对象,因为它不再是编辑器的预制件(它被你重新分配)。 对不起,我必须删除以前的答案。 反正这是错的。 The first instantiation may be successf ...
  • 如果你这样写: new Game (); 这是通过使用构造函数完成的。 构造函数的主要目的是创建对象并初始化任何变量并设置您需要设置的任何初始值。 如果你只编写new Game() ,它可以编译,但并不意味着它是一个很好的实现方式。 为什么它不是一个好的实现? 这是因为这样做,你就像在构造函数中编写entire game一样好。 首先是错误的,因为实际上你不应该在构造函数中实现你的整个逻辑。 那么为什么人们会这样做: Game g = new Game(); g.gameLoop(); 现在,请注意这个 ...
  • 在可能的情况下,最好避免使用循环引用; 但是如果你真的想这样做,那么解决方案是在头文件的顶部向前声明你的类Game ,它将使用引用/指针。 例如 #ifndef EVENTH #define EVENTH class Game; class Event { Game* game; }; #endif 和.. #ifndef PLAYERH #define PLAYERH class Game; class Player { Game* game; }; #endif 对于不需 ...
  • 第一个问题如果数组的唯一用法是遍历对象,那么我会说它是多余的。 如果数组的索引具有某种意义,并且它允许您更快地访问特定对象,那么可能会有一些好处。 第二个问题我完全避免使用可变类静态变量。 它们基本上等同于全局变量。 First question If the only usage for the array is iterating through the objects, then I'd say it's redundant. If the indices to the array have some ...
  • 这似乎可以通过一种解决方法来实现,其中sceneLoaded事件启动一个协程,等待下一帧。 下面的相关代码段。 作为参考,我最近在Unityforums上阅读了这个帖子: https ://forum.unity3d.com/threads/scenemanager-sceneloaded-event-when-fired-checking-scene-isloaded-false.429659/ void Awake () { instance = this; DontDestroyOnL ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。