Sign in to follow this  
Followers 0
AlienStar

file copy ... but !!!!!

15 posts in this topic

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 ?????? ...

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 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

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 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)

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by AlienStar

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by Malcy

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by AlienStar

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 .....

Share this post


Link to post
Share on other sites

oh. just work with that. use the help file. i may be missing something, ill check it later, got stuff to do

ok billthecreator

I'll try too coz it's really so important

thanks anyway for help

Share this post


Link to post
Share on other sites

i know what i did.. i for got to put the $File where the "File.txt" is. maybe that will work

I'm sorry also it didn't work

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

#15 ·  Posted (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 :

#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 by AlienStar

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