Jump to content

_FileChangeRecursive()


/dev/null
 Share

Recommended Posts

Hi,

here is my contribution to a reccuring problem. Ever wanted to

change something in, or do something with a lot of files? Here

is my solution.

_FileChangeRecursive()

This functions finds files based on a given pattern (like FileFindFirstFile),

while it walks recursively through a given directory tree (up to a given

recursion level). Then it takes the files that match the pattern, and

pass them to a "worker function", one by one. That worker function actually

does the job of "changing" the files.

Sample #1

Task: Rename all files *.au3 -> *.au4

Function Call:

$retval = _FileChangeRecursive("C:\temp\autoit","*.au3",-1,"_RenameFile",".au4")oÝ÷ Ùµ¨®G«~éܶ*'ý¶®¶­s`¦gVæ2õ&VæÖTfÆRb33c¶fÆWFÂb33c¶WFVç7Föâ Æö6Âb33c·'G2Ò7G&æu7ÆBb33c¶fÆWFÂgV÷C²âgV÷C² Æö6Âb33c¶æWwFÒgV÷C²gV÷C° f÷"b33c¶âÒFòb33c·'G5³ÒÓ b33c¶æWwFf׳Òb33c·'G5²b33c¶åÐ æW@  fÆTÖ÷fRb33c¶fÆWFÂb33c¶æWwFfײb33c¶WFVç7Föâ¦VæFgVæ0 oÝ÷ Ù´^ÛöÛM«$ý³æiÉ.¦ÚWâë-¡Ø}êÞ×b­ç-¢¼©­ë®÷­çè׫²ÚîrÛ«y±nËb¢p_Ûjëh×6$retval = _FileChangeRecursive("C:\temp\autoit","*.au3",-1,"_BackupFile","C:\temp\autoit","c:\temp\backup")oÝ÷ Ùµ¨®G«~éܶ*'ý¶®¶­s`¦gVæ2ô&6·WfÆRb33c¶fÆWFÂb33c¶&6WFÂb33c¶&6·WföÆFW" Æö6Âb33c·&VÇFÒ7G&æu&WÆ6Rb33c¶fÆWFÂb33c¶&6WFÂgV÷C²gV÷C² fÆT6÷b33c¶fÆWFÂb33c¶&6·WföÆFW"fײb33c·&VÇFó¦VæFgVæ0

As you can see, you'll have to pass the name of the worker function and

all function parameters for the worker (up to 5 parameters are

possible).

The benefit of _FileChangeRecursive()is that you have one function that

searches the files recursively and you can write several "worker" functions

without the need to change a single line of _FileChangeRecursive().

For more samples see the attached files. Documentation is in the

function code itself!

Have fun!

Cheers

Kurt

_FileChangeRecursive.au3

_FileChangeRecursive_Samples.au3

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Brilliant. Somebody actually using Call() for the purpose I re-designed it for.

Thanks!

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

  • Moderators

Hi everybody!

@ /dev/null:

I like this UDF a lot, thanks for sharing it. I'm PMing you some comments

alc

The MVPs can only receive PMs from someone that has over 250 posts or has been on the board for at least 6 months. You're best bet is to PM Valik, he will give you the proper reply based on the relevance and intelligence of your PM.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

The MVPs can only receive PMs from someone that has over 250 posts or has been on the board for at least 6 months. You're best bet is to PM Valik, he will give you the proper reply based on the relevance and intelligence of your PM.

:whistle::)

Anyway, too late....

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

  • Moderators

Don't encourage people to PM me. I get enough crap as is. Encourage people to post in public threads so we can all have a go at them.

I would have thought that to be discouragement to PM anyone... :whistle: ... but I agree whole heartedly!!

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

@ /dev/null: What means too late?

never mind, all O.K. It will take some time to answer your PM, as it's a bit "lengthy". BTW can you post or PM the modifications you have made? Thanks!

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Ok, but I need to finished it and polish the look. Give me some time, cause right now my boss is standing behind me and asking for some results he is expecting. I'll try to post it today, but don't sure I'll have time, may be I'll have to post on Monday, I don't have Internet at home. Ok?

Just in case, happy weekend for everybody

O.K. Have a nice weekend!

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Hi alc,

as I posted the code here, your are free to use and modify based on your needs. So, go ahead and change whatever you like...

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

  • 4 weeks later...

Hi and thanks a lot for your script.

I'm using it and I really like it. that's a great job you have done.

I wish to have other functionnalities :

=> choose folder / file or Folder+file

=> an array of file exceptions to work on *.* but not *.zip nor *.rar etc.

I made a little function to be used with your script.

please feel free to used it.

any comment/suggestion are welcome.

CODE

; Compact an access database

; required At least MDAC 2.1

; No access installation is needed

;

; $Destination must be different from $Source

;

; $Replace

; 0 => keep $Source and $Destination file

; 1 => replace $Source with $Destination ; keep $Destination file

; 2 => replace $Source with $Destination ; remove $Destination file

;

func _CompactMDB($Source,$Destination, $Replace=0)

If FileExists($Source) Then

if FileExists($Destination)=0 Then

$oMDB = ObjCreate("JRO.JetEngine")

If IsObj($oMDB) Then

$oMDB.CompactDatabase( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & $Source, "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & $Destination)

EndIf

Switch $Replace

case 1

filecopy( $Destination, $Source, 1+8)

case 2

filemove( $Destination, $Source, 1+8)

EndSwitch

EndIf

EndIf

endFunc

Edited by Krem
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...