Sign in to follow this  
Followers 0
stlcomptchr

Script Needed

3 posts in this topic

Hi. I'm quite new to AutoIt. I'm looking for a script that will allow me to open file, save as with an incremental name, close the file; then open it again, save w/incremental name, close. For example:

Open File1

Save as File2

Open File2

Save as File3

Open File3

Save as File4.

My guess is there is a script "out there" that does this. Can anybody guide me there?

Thanks!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

$numberOfFiles = 10
$dir = "C:\directory\of\your\file"
filechangedir($dir)
$file = "file1.txt"
for $i = 0 to $numberOfFiles
    fileCopy($file,"file" & $i & ".txt")
$file = "file" & $i & ".txt"
next

should work :)

Edited by torels

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

$numberOfFiles = 10

$dir = "C:\directory\of\your\file"

filechangedir($dir)

$file = "file1.txt"

for $i = 0 to $numberOfFiles

fileCopy($file,"file" & $i & ".txt")

$file = "file" & $i & ".txt"

next

wont work

since file2.txt exists, it wont be overwritten

if you use it with flag 1 (overwrite) then the effect is to copy file1 -> file2 -> file3 ----> file : now all files will have the same content as file 1 !

@stlcomptchr

please specify if all files previously exist, or if you have some kind of logging system which should keep up to x files for backup, to keep e.g. up to x instances of a file?

the trick is to count backwards, not forwards

so the code would be something like this

$numberOfFiles = 10

$file = $numberOfFiles & ".txt"

for $i = $numberOfFiles to 1 step - 1
    $j = $i + 1 
    
    $sourcefile = @ScriptDir & "\" & $i &".txt";
    $destfile   = @ScriptDir & "\" & $j &".txt";
    
    $rc = FileMove($sourcefile, $destfile ,1 )
next
Edited by nobbe

Share this post


Link to post
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
Sign in to follow this  
Followers 0