Jump to content

copy/move issue


Recommended Posts

Hi,

I'm having some difficulty copying/moving a file, here is the code I'm using:

; Shows the filenames of all files in the current directory.

$search = FileFindFirstFile("C:\SegFiles\BACKS\*.txt")

;copy the file to another directory, overwrite if a file is there already with the same name

FileCopy("C:\SegFiles\BACKS\" & $search, "C:\My Documents\17Closes.inp", 9)

The file is not being copied in the new Directory, the script compiles fine, can somebody point out the error here? Thank you in advance.

Link to comment
Share on other sites

  • Developers

Have a look at the helpfile for the example. FileFindFirst will:

Return Value

Success: Returns a search "handle" for use with subsequent FileFindNextFile functions

Not a filename.

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Thanks for the info, based upon that, I thought I could pass that handle to another variable and use it that way, but I see no difference in the behaviour. So I'm now doing this:

; Shows the filenames of all files in the current directory.

$search = FileFindFirstFile("C:\SegFiles\BACKS\*.txt")

$use = $search

;copy the file to another directory, overwrite if a file is there already with the same name

FileCopy("C:\SegFiles\BACKS\" & $use, "C:\My Documents\17Closes.inp", 9)

Link to comment
Share on other sites

  • Developers

Now did you look at the example in the Helpfile which is at the bottom of the page explaining FileFindFirst?

You need the FileFindNExt() statement.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I'm sorry I'm new to this app. so I'm not following you. I have the statement later in my code as such:

; Shows the filenames of all files in the current directory.

$search = FileFindFirstFile("C:\SegFiles\BACKS\*.txt")

$use = $search

;copy the file to another directory, overwrite if a file is there already with the same name

FileCopy("C:\SegFiles\BACKS\" & $use, "C:\My Documents\17Closes.inp", 9)

...stuff

;go to next file in Directory to repeat process

$file = FileFindNextFile($search)

Forgive me but I don't understand what you're driving at...what does the FileFindNextFile statement have to do with appending the correct handle to the Copy command?

Link to comment
Share on other sites

  • Developers

I don't mind helping but you have ignored my question now for the second time. Have you looked at the helpfile example ?

It explains how the function should be used.

:)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I have not ignored it, I have looked at it several times, and in fact basically have it cut and pasted into my code. It does not explain to me the logic of the process.

The way I'm reading it is that the FileFindFirstFile finds the "first" file in the Directory and assigns it a handle called "$search". I then want to do several things to process this first file (including copying and moving it)...the FileFindNextFile($search) then takes the "next" file (and all remaining others) in the Directory and assigns the handle "$file" to them...if the FileFindNextFile($search) is called after the copy/move how am I to get that first file processed as I wish?

Link to comment
Share on other sites

  • Developers

Ok Understrand your confusion.

FileFindFirst(0 returns a handle for the Search nothing more.

The first time FileFileNext() is ran, the first file is returned that matches the search argument as defined in FileFindFirst().

So you always require the execution of at least one time FileFileNext() to get the first matching file.

:)

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

OK I guess that makes sense, but it makes me wonder why there is any need to have 2 seperate command statements...confusing. However that is another (unimportant) issue. Thanks again.

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