Jump to content

Recommended Posts

Posted

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?

Posted (edited)
  On 12/31/2020 at 11:37 PM, GokAy said:

@MyDocumentsDir & "\OneMoreFolder"

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

Expand  

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
Posted
  On 12/31/2020 at 11:52 PM, 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)

 

Expand  

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?

Posted
  On 12/31/2020 at 11:58 PM, 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?

Expand  

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

Posted

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?

Posted
  On 1/1/2021 at 12:11 AM, 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)

 

Expand  

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

Posted
  On 1/1/2021 at 12:03 AM, GokAy said:

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

Expand  

 

  On 1/1/2021 at 12:53 AM, JockoDundee said:

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

Expand  

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

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.

  On 1/1/2021 at 4:42 AM, 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”

Expand  

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

"I think you are searching a bug where there is no bug... don't listen to bad advice."

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