Sign in to follow this  
Followers 0
Zithen

auto increment file extention

5 posts in this topic

making a script that will be a file when ran, but i dont want it to overwite the existing file if it finds it. would like to have it name .000 then increment if it already exists too. how can i go about doing this?

Share this post


Link to post
Share on other sites



heh...looking at that and thinking about it, i feel dumb...its so easy its gotta work

use something like

$variable = 0

while 1

if fileexists( "string" & $variable) then $variable += 1

$name = "string" & $variable

wend

Share this post


Link to post
Share on other sites

$variable = 0
while fileexists( "Filename." & StringFormat("%03i",$variable))
    $variable = $variable + 1
wend
$Filename = "Filename." & StringFormat("%03i",$variable)


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

or maybe this

#include <GUIConstants.au3>
Dim $location
 

; opens a new file every time script is ran
; or New File button is pressed
New_file()


GUICreate("GUICtrlCreateDummy",450,100, 100,200)


$user = GUICtrlCreateDummy()
$button = GUICtrlCreateButton ("New File",40,70,70,20)
$cancel = GUICtrlCreateButton ("Cancel",150,70,70,20)
$notice = GUICtrlCreateLabel($location, 20, 20, 400, 20, $SS_SUNKEN)
GUISetState()

Do
  $msg = GUIGetMsg ()
     
   Select
   Case $msg = $button
        New_file()
        MsgBox(0,"new file name", $location & "   " )
        GUICtrlSetData($notice, $location)
      Case $msg = $cancel
        exit
      Case $msg = $user
        ; special action before closing
        ; ...
         exit
   EndSelect
Until $msg = $GUI_EVENT_CLOSE

;---------------------------  Start - Functions ------------------------------------------

Func New_file()
    For $x = 1 to 1000
    If Not FileExists(@ScriptDir & "\test"& $x & ".txt" ) Then
        FileWrite(@ScriptDir & "\test"& $x & ".txt", "File Started " & @MDAY & "-" & @MON & "-" & @YEAR )
        $location = @ScriptDir & "\test"& $x & ".txt"
        ExitLoop
    EndIf
Next
EndFunc

8)


NEWHeader1.png

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