AlienStar Posted August 19, 2009 Share Posted August 19, 2009 hello everybody I wanna add a condition to my script but I can't .... for example : FileCopy("File.txt","file1.txt",) I wanna : at first time : copy File.txt to file1.txt but the next time when I run the script ... copy File.txt to another name something like file2.txt and each time the script run ... copy File.txt to different name isn't existed in this way the number of copied files rise each time the script run please .... any body help me ?????? ... Link to comment Share on other sites More sharing options...
billthecreator Posted August 19, 2009 Share Posted August 19, 2009 (edited) For $x=1 To 5; change this number If Not FileExists("file" & $x & ".txt") Then FileCopy("File.txt","file" & $x & ".txt") ExitLoop EndIf Next i havent tested this, but it might work. Edited August 19, 2009 by billthecreator [font=Microsoft Sans Serif]My Scripts: From Most recent to least.[/font]Countdown GUI | QLOCK TWO | FlipClock | Slot Machine My UDF:_GenerateRandomNoRepeat | _GuiSnap Link to comment Share on other sites More sharing options...
JSThePatriot Posted August 19, 2009 Share Posted August 19, 2009 (edited) For $x=1 To 5; change this number If Not FileExists("file" & $x & ".txt") Then FileCopy("File.txt","file" & $x & ".txt") ExitLoop EndIf Next i havent tested this, but it might work. @bill What you have said above would simply write out 5 files. He would need to store the last number he did, or search the drive for the latest number (if it exists), and then plus one to it. Wow...I need to go home. I missed the "ExitLoop" >_< Edit01: Had a brain malfunction...gonna go home in 20 minutes. Jarvis Edited August 19, 2009 by JSThePatriot AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more) Link to comment Share on other sites More sharing options...
AlienStar Posted August 19, 2009 Author Share Posted August 19, 2009 (edited) For $x=1 To 5; change this number If Not FileExists("file" & $x & ".txt") Then FileCopy("File.txt","file" & $x & ".txt") ExitLoop EndIf Next i havent tested this, but it might work. I don't know what I can say ...... it works !!!!!!!!!!!! really you are soooooooooooooooooooo amazing . but how can I put number to infinity ??? and how can I put a directory for File.txt for example if this file is in C:\folder ???? thanks so so so so so so much Edited August 19, 2009 by AlienStar Link to comment Share on other sites More sharing options...
Malkey Posted August 19, 2009 Share Posted August 19, 2009 (edited) I don't know what I can say ...... it works !!!!!!!!!!!! really you are soooooooooooooooooooo amazing . but how can I put number to infinity ??? and how can I put a directory for File.txt for example if this file is in C:\folder ???? thanks so so so so so so much Like this. ; Local $x = 0 While 1 $x += 1 If Not FileExists("C:\folder\file" & $x & ".txt") Then FileCopy("File.txt", "C:\folder\file" & $x & ".txt",8) ExitLoop EndIf WEnd ;C:\Documents and Settings\mc\Local Settings\Temp Edit: Added save to different directory. Edited August 19, 2009 by Malcy Link to comment Share on other sites More sharing options...
AlienStar Posted August 19, 2009 Author Share Posted August 19, 2009 (edited) Like this. ; Local $x = 0 While 1 $x += 1 If Not FileExists("file" & $x & ".txt") Then FileCopy("File.txt", "file" & $x & ".txt") ExitLoop EndIf WEnd ; now it's better .... thanks so much you are all reliable bodies but I wanna put a directory for File.txt when the script was near File.txt it works but I wanna put script in D:\ ( for example ) and File.txt in C:\folder again ... thanks toooooooooo much Edited August 19, 2009 by AlienStar Link to comment Share on other sites More sharing options...
billthecreator Posted August 19, 2009 Share Posted August 19, 2009 glad to help. just check for Directory. if its not there, then create. $Dir = "D:\FileFolder" ; Change as you wish If Not FileExists($Dir) Then DirCreate($Dir) $File = $Dir & "\" & "File.txt" Local $x = 0 While 1 $x += 1 If Not FileExists($Dir & "\file" & $x & ".txt") Then FileCopy("File.txt", $Dir & "\file" & $x & ".txt", 8) ExitLoop EndIf WEnd [font=Microsoft Sans Serif]My Scripts: From Most recent to least.[/font]Countdown GUI | QLOCK TWO | FlipClock | Slot Machine My UDF:_GenerateRandomNoRepeat | _GuiSnap Link to comment Share on other sites More sharing options...
AlienStar Posted August 19, 2009 Author Share Posted August 19, 2009 glad to help. just check for Directory. if its not there, then create. $Dir = "D:\FileFolder" ; Change as you wish If Not FileExists($Dir) Then DirCreate($Dir) $File = $Dir & "\" & "File.txt" Local $x = 0 While 1 $x += 1 If Not FileExists($Dir & "\file" & $x & ".txt") Then FileCopy("File.txt", $Dir & "\file" & $x & ".txt", 8) ExitLoop EndIf WEnd sorry man ... it didn't work ..... Link to comment Share on other sites More sharing options...
billthecreator Posted August 19, 2009 Share Posted August 19, 2009 oh. just work with that. use the help file. i may be missing something, ill check it later, got stuff to do [font=Microsoft Sans Serif]My Scripts: From Most recent to least.[/font]Countdown GUI | QLOCK TWO | FlipClock | Slot Machine My UDF:_GenerateRandomNoRepeat | _GuiSnap Link to comment Share on other sites More sharing options...
AlienStar Posted August 19, 2009 Author Share Posted August 19, 2009 oh. just work with that. use the help file. i may be missing something, ill check it later, got stuff to dook billthecreator I'll try too coz it's really so important thanks anyway for help Link to comment Share on other sites More sharing options...
billthecreator Posted August 19, 2009 Share Posted August 19, 2009 i know what i did.. i for got to put the $File where the "File.txt" is. maybe that will work [font=Microsoft Sans Serif]My Scripts: From Most recent to least.[/font]Countdown GUI | QLOCK TWO | FlipClock | Slot Machine My UDF:_GenerateRandomNoRepeat | _GuiSnap Link to comment Share on other sites More sharing options...
Yashied Posted August 20, 2009 Share Posted August 20, 2009 Always use the FULL paths to files and you will not have problems. My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
AlienStar Posted August 20, 2009 Author Share Posted August 20, 2009 i know what i did.. i for got to put the $File where the "File.txt" is. maybe that will workI'm sorry also it didn't work Link to comment Share on other sites More sharing options...
JSThePatriot Posted August 20, 2009 Share Posted August 20, 2009 I would like to point out that you're not doing any error checking to be sure the functions are performing as they are supposed to. Check the help file for each function you're using and write some error checking. It should point you to "why" it's not working. There is no need to call the DirCreate as you do that in FileCopy(), check the help file for the last parameter. So I would do the following...$Dir = "D:\FileFolder" ; Change as you wish $File = $Dir & "\" & "File.txt" Local $x = 0 While 1 $x += 1 If Not FileExists($Dir & "\file" & $x & ".txt") Then FileCopy($File, $Dir & "\file" & $x & ".txt", 8) ExitLoop EndIf WEnd You will notice, I didn't add error checking. I'm going to leave that to you to figure out. You really need to check the FileCopy and see if it worked for you or not. That's your main function call, and you're not even sure if it's being called correctly. I hope this helps some, Jarvis AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more) Link to comment Share on other sites More sharing options...
AlienStar Posted August 20, 2009 Author Share Posted August 20, 2009 (edited) I would like to point out that you're not doing any error checking to be sure the functions are performing as they are supposed to. Check the help file for each function you're using and write some error checking. It should point you to "why" it's not working. There is no need to call the DirCreate as you do that in FileCopy(), check the help file for the last parameter. So I would do the following...$Dir = "D:\FileFolder" ; Change as you wish $File = $Dir & "\" & "File.txt" Local $x = 0 While 1 $x += 1 If Not FileExists($Dir & "\file" & $x & ".txt") Then FileCopy($File, $Dir & "\file" & $x & ".txt", 8) ExitLoop EndIf WEnd You will notice, I didn't add error checking. I'm going to leave that to you to figure out. You really need to check the FileCopy and see if it worked for you or not. That's your main function call, and you're not even sure if it's being called correctly. I hope this helps some, Jarvis I wanna thank you so much . it works !!!!!!!!!!!!!! now I wanna tell you what I intend to use this script : I'm making a CD magazine and wanna each time the I use this magazine give me the number of using ................ How ???? I use this script to search for File.txt and if not existed create , also its folder ( this is in the first run ) in the next times : if File.txt is existed copy to another name this is the script : #RequireAdmin ; Shows the filenames of all files in the current directory $Dir = @MyDocumentsDir & "\My Pictures\temp\" $search = FileFindFirstFile(@MyDocumentsDir & "\My Pictures\temp\file.txt") ; Check if the search was successful If $search = -1 Then ; Prompt the user to run the script - use a Yes/No prompt (4 - see help file) If Not FileExists($Dir) Then DirCreate($Dir) FileWrite (@MyDocumentsDir & "\My Pictures\temp\File.txt","Text") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop ; here if File.txt is found copy to another name : $File = $Dir & "\" & "File.txt" Local $x = 0 While 1 $x += 1 If Not FileExists($Dir & "\file" & $x & ".txt") Then FileCopy($File, $Dir & "\file" & $x & ".txt", 8) ExitLoop EndIf WEnd WEnd ; Close the search handle FileClose($search) then I know the number of times of using by this script when run each time : #RequireAdmin #Include <File.au3> #Include <Array.au3> $FileList=_FileListToArray(@MyDocumentsDir & "\My Pictures\temp\") If (Not IsArray($FileList)) and (@Error=1) Then MsgBox (0,"","No Files\Folders Found.") Exit EndIf If $FileList[0] = 1 Then MsgBox(64,"Thanks for using"," you're welcome ..... This is the first time you use our magazine " ) Elseif $FileList[0] = 2 Then MsgBox(64,"Thanks for using "," you're welcome ..... This is the second time you use our magazine " ) Elseif $FileList[0] = 3 Then MsgBox(64,"Thanks for using"," you're welcome ..... This is the third time you use our magazine " ) Else MsgBox(64,"Thanks for using", & $FileList[0] " times you've been using our magazine until this time " ) EndIf all these scripts are working now and all of this thanks to your wonderful works and helps ( I never forget this for everyone helps me ) when I join this two scripts to one it works but send message with number of files except the latest one ( I don't know why ) this is the joined script : expandcollapse popup#RequireAdmin #Include <File.au3> #Include <Array.au3> ; Shows the filenames of all files in the current directory $Dir = @MyDocumentsDir & "\My Pictures\temp\" $search = FileFindFirstFile(@MyDocumentsDir & "\My Pictures\temp\file.txt") $FileList=_FileListToArray(@MyDocumentsDir & "\My Pictures\temp\") ; Check if the search was successful If $search = -1 Then ; Prompt the user to run the script - use a Yes/No prompt (4 - see help file) If Not FileExists($Dir) Then DirCreate($Dir) FileWrite (@MyDocumentsDir & "\My Pictures\temp\File.txt","Text") MsgBox(64,"hi"," this is the first time the magazine run " ) Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop $File = $Dir & "\" & "File.txt" Local $x = 0 While 1 $x += 1 If Not FileExists($Dir & "\file" & $x & ".txt") Then FileCopy($File, $Dir & "\file" & $x & ".txt", 8) ExitLoop EndIf WEnd If (Not IsArray($FileList)) and (@Error=1) Then MsgBox (0,"","No Files\Folders Found.") Exit EndIf If $FileList[0] = 2 Then MsgBox(64,"Thanks for using CEM"," you're welcome ..... This is the second time you use our magazine " ) Elseif $FileList[0] = 3 Then MsgBox(64,"Thanks for using CEM"," you're welcome ..... This is the third time you use our magazine " ) Elseif $FileList[0] = 4 Then MsgBox(64,"Thanks for using CEM"," you're welcome ..... This is the forth time you use our magazine " ) Else MsgBox(64,"Thanks for using CEM", & $FileList[0] " times you've been using our magazine until this time " ) EndIf WEnd ; Close the search handle FileClose($search) MsgBox (0,"","No Files\Folders Found.") will not be send coz the script create File.txt now what are the faults in this script ????? Edited August 20, 2009 by AlienStar Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now