Jump to content
ronen1n

Copy and replace file in Documents folder

Recommended Posts

Hello

I need to replace a file in documents folder that i changed is place.

I cant find it with %USERPROFILE% i can find it with cmd like this:

reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Personal

How can i do it in autoit?

Share this post


Link to post
Share on other sites
9 minutes ago, GokAy said:

@MyDocumentsDir & "\OneMoreFolder"

By the way, yellow can't be read on white background.

Yes I forgot the \ and tried to add it but you posted
Its automaticly changed it to yellow 

Now I got this code but its not working
 

FileCopy("\file.*", @MyDocumentsDir & "\folder\file.*", 8)

 

Edited by ronen1n

Share this post


Link to post
Share on other sites

It is Source, Dest so this should be enough, no need for filename in Dest. (Removed inaccurate info)

FileCopy(@MyDocumentsDir & "\file.*", @MyDocumentsDir & "\folder\",8)

Edit: Also you say you want to move the file, so FileMove would be better (which can also rename)

https://www.autoitscript.com/autoit3/docs/functions/FileMove.htm

Edited by GokAy

Share this post


Link to post
Share on other sites
1 minute ago, GokAy said:

It is Source, Dest so this should be enough, no need for filename in Dest if you don't want to rename.

FileCopy(@MyDocumentsDir & "\file.*", @MyDocumentsDir & "\folder\",8)

 

But the Source of the file is anyware the script is runing from not in @MyDocumentsDir

The file is in the same folder with the script and i dont want to change the script any time i change the folder location

Can i do it?

Share this post


Link to post
Share on other sites
1 minute ago, ronen1n said:

But the Source of the file is anyware the script is runing from not in @MyDocumentsDir

The file is in the same folder with the script and i dont want to change the script any time i change the folder location

Can i do it?

No need for the trailing \ in the destination.

Where the script runs from shouldn’t matter as the paths are absolute.


Code hard, but don’t hard code...

Share this post


Link to post
Share on other sites
2 minutes ago, JockoDundee said:

No need for the trailing \ in the destination.

You don't? The example in the document uses it..

Share this post


Link to post
Share on other sites

I think you dont get me 

E:\\ChangingPathSomeTimes\script.exe + FileToCopy.*

Can i copy from the script folder what ever the path will be to the Documents?

Share this post


Link to post
Share on other sites
7 minutes ago, GokAy said:

Yes.. I answered that, maybe it was not obvious.

FileCopy(@ScriptDir & "\file.*", @MyDocumentsDir & "\folder\",8)

According to JockoDundee you don't need "\", so:

FileCopy(@ScriptDir & "\file.*", @MyDocumentsDir & "\folder",8)

 

I sew the @ScriptDir somewhere else but didn't get what its doing

And Yes its working without the \ and I think in CMD its working without it too but it's more understandable

Thank you

Share this post


Link to post
Share on other sites
48 minutes ago, GokAy said:

You don't? The example in the document uses it..

Good eye.  I've always used it like a Copy or cp statement destination, never gave it a second thought...


Code hard, but don’t hard code...

Share this post


Link to post
Share on other sites
1 hour ago, GokAy said:

You don't? The example in the document uses it..

 

55 minutes ago, JockoDundee said:

Good eye.  I've always used it like a Copy or cp statement destination, never gave it a second thought...

So i found out that the path without the \ and the path doesn't exist he think that it's file and creates file with the last folder name so it's better to add it anyway

Share this post


Link to post
Share on other sites
2 hours ago, ronen1n said:So i found out that the path without the \ and the path doesn't exist he think that it's file and creates file with the last folder name so it's better to add it anyway

good find.  So what’s it do in the case of

FileCopy("C:\SomeDir\file.*", @MyDocumentsDir & "\folder")

if there are multiple file.* and no directory named “folder”


Code hard, but don’t hard code...

Share this post


Link to post
Share on other sites
Posted (edited)

A year ago, I described exactly the same issue in this link, where my voluntary inexistant destination folder (named "Administrateur2") corresponds to the folder named "folder" in your example.

1 hour ago, JockoDundee said:

So what’s it do in the case of

FileCopy("C:\SomeDir\file.*", @MyDocumentsDir & "\folder")

if there are multiple file.* and no directory named “folder”

In your case, all your source files named file.* will be copied under a single file name (the file name will be... "folder") and each source file copied will constantly overwrite the precedent copied file named "folder", all this without any error returned by the FileCopy function (this explanation corresponds to the presence of a 3rd parameter which allows you to overwrite existing files, as in the example below)

To avoid this issue, I think it's better to use the following syntax, even if the help file (topic FileCopy) doesn't stipulate that you are allowed to indicate file names in the destination parameter :

#include <FileConstants.au3>

$iStatus = FileCopy("C:\SomeDir\file.*", @MyDocumentsDir & "\folder\file.*",  $FC_OVERWRITE)
If $iStatus = 0 Then ; FileCopy went wrong (for example \folder doesn't exist)
    ; your error message here
EndIf

 

Edited by pixelsearch
some changes in explanations, depending on the presence (or not) of the 3rd parameter to overwrite

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...