ronen1n 1 Posted December 28, 2020 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
Nine 993 Posted December 28, 2020 try : Local $sEnvVar = EnvGet("USERPROFILE") MsgBox (0,"",$sEnvVar) Not much of a signature but working on it... Spoiler Block all input without UAC Save/Retrieve Images to/from Text Tool to search content in au3 files Date Range Picker Sudoku Game 2020 Overlapped Named Pipe IPC x64 Bitwise Operations Multi-keyboards HotKeySet Fast and simple WCD IPC GIF Animation (cached) Share this post Link to post Share on other sites
JockoDundee 156 Posted December 29, 2020 MsgBox (0,"",@MyDocumentsDir) 1 ronen1n reacted to this Code hard, but don’t hard code... Share this post Link to post Share on other sites
ronen1n 1 Posted December 31, 2020 (edited) How can i get inside one more folder? I tried this and it didnt work @MyDocumentsDir\OneMoreFolder Ok i found it @MyDocumentsDir & "OneMoreFolder" Now i cant find the option to copy file from the script folder Edited December 31, 2020 by ronen1n Share this post Link to post Share on other sites
GokAy 60 Posted December 31, 2020 @MyDocumentsDir & "\OneMoreFolder" By the way, yellow can't be read on white background. Share this post Link to post Share on other sites
ronen1n 1 Posted December 31, 2020 (edited) 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 December 31, 2020 by ronen1n Share this post Link to post Share on other sites
GokAy 60 Posted December 31, 2020 (edited) 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 December 31, 2020 by GokAy Share this post Link to post Share on other sites
ronen1n 1 Posted December 31, 2020 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
GokAy 60 Posted January 1 (edited) In that case use @ScriptDir Check out Macros page for a list of possible known locations: https://www.autoitscript.com/autoit3/docs/macros.htm Edited January 1 by GokAy Share this post Link to post Share on other sites
JockoDundee 156 Posted January 1 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. 1 ronen1n reacted to this Code hard, but don’t hard code... Share this post Link to post Share on other sites
GokAy 60 Posted January 1 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
ronen1n 1 Posted January 1 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
GokAy 60 Posted January 1 (edited) 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) Edited January 1 by GokAy 1 ronen1n reacted to this Share this post Link to post Share on other sites
ronen1n 1 Posted January 1 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
JockoDundee 156 Posted January 1 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
ronen1n 1 Posted January 1 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 1 GokAy reacted to this Share this post Link to post Share on other sites
GokAy 60 Posted January 1 Thanks for the clarification. Share this post Link to post Share on other sites
JockoDundee 156 Posted January 1 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
pixelsearch 226 Posted January 1 (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 January 1 by pixelsearch some changes in explanations, depending on the presence (or not) of the 3rd parameter to overwrite 1 GokAy reacted to this Share this post Link to post Share on other sites