Jump to content

I want to replace files in Folders in other Folders


Eazy-P
 Share

Go to solution Solved by ioa747,

Recommended Posts

  • Solution

this find all test*.txt (test1.txt , test2.txt etc) in folder @ScriptDir & "\kfc\ and its subfolder and replaced with @ScriptDir & "\NewTest.txt"

here the initial name replaced with NewTest.txt

#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#include <File.au3>

_FindAllFile()

;----------------------------------------------------------------------------------------
Func _FindAllFile()
    Local $dir = @ScriptDir & "\kfc\"    ; <------------
    Local $ArraySrtfiles = _FileListToArrayRec($dir, "test*.txt", $FLTAR_FILES, $FLTAR_RECUR)
    If Not IsArray($ArraySrtfiles) Then
        ConsoleWrite($dir & " = Invalid input path" & @CRLF)
        Return
    Else
        For $x = 1 To $ArraySrtfiles[0]
            ;ConsoleWrite($dir & $ArraySrtfiles[$x]& @CRLF)
            _ReplaceTxt($dir & $ArraySrtfiles[$x])
        Next
    EndIf
EndFunc   ;==>_FindAllFile
;----------------------------------------------------------------------------------------
Func _ReplaceTxt($TxtFile)
    Local $sName = "\NewTest.txt"
    Local $NewTxtFile = @ScriptDir & $sName

    ;ReplaceTxt
    FileCopy($NewTxtFile, $TxtFile, $FC_OVERWRITE + $FC_CREATEPATH)

    Local $sFolder = StringLeft($TxtFile, StringInStr($TxtFile, "\", $STR_NOCASESENSEBASIC, -1) -1)

    ;FileRename
    FileMove($TxtFile, $sFolder & $sName, $FC_OVERWRITE + $FC_CREATEPATH)

EndFunc   ;==>_ReplaceTxt

 

I know that I know nothing

Link to comment
Share on other sites

47 minutes ago, ioa747 said:

this find all test*.txt (test1.txt , test2.txt etc) in folder @ScriptDir & "\kfc\ and its subfolder and replaced with @ScriptDir & "\NewTest.txt"

here the initial name replaced with NewTest.txt

#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#include <File.au3>

_FindAllFile()

;----------------------------------------------------------------------------------------
Func _FindAllFile()
    Local $dir = @ScriptDir & "\kfc\"    ; <------------
    Local $ArraySrtfiles = _FileListToArrayRec($dir, "test*.txt", $FLTAR_FILES, $FLTAR_RECUR)
    If Not IsArray($ArraySrtfiles) Then
        ConsoleWrite($dir & " = Invalid input path" & @CRLF)
        Return
    Else
        For $x = 1 To $ArraySrtfiles[0]
            ;ConsoleWrite($dir & $ArraySrtfiles[$x]& @CRLF)
            _ReplaceTxt($dir & $ArraySrtfiles[$x])
        Next
    EndIf
EndFunc   ;==>_FindAllFile
;----------------------------------------------------------------------------------------
Func _ReplaceTxt($TxtFile)
    Local $sName = "\NewTest.txt"
    Local $NewTxtFile = @ScriptDir & $sName

    ;ReplaceTxt
    FileCopy($NewTxtFile, $TxtFile, $FC_OVERWRITE + $FC_CREATEPATH)

    Local $sFolder = StringLeft($TxtFile, StringInStr($TxtFile, "\", $STR_NOCASESENSEBASIC, -1) -1)

    ;FileRename
    FileMove($TxtFile, $sFolder & $sName, $FC_OVERWRITE + $FC_CREATEPATH)

EndFunc   ;==>_ReplaceTxt

 

Thanks this is what i was looking for! thanks alot just needed to declare the var before the functions and it worked

Link to comment
Share on other sites

Now @ioa747 😂 , your post (your solution) does almost the same like my post before. The funny thing is that we come up with different approaches and different understandings what @Eazy-P was wanting and at the end we suggest almost the same way. I like that 😀 . See you later.

Best regards
Sven

Edited by SOLVE-SMART

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

22 hours ago, ioa747 said:

Thanks If you have any question ask

Hi i do have a question. What does #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 do? Yout put it at the top of your script.

Link to comment
Share on other sites

  • Developers

This is used by AutoIt3Wrapper to add those parameters to the au3check step, so this will only do something when you have the separate SciTE4AutoIt3 installer installed.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...