ronen1n Posted December 28, 2020 Share 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? Link to comment Share on other sites More sharing options...
Nine Posted December 28, 2020 Share Posted December 28, 2020 try : Local $sEnvVar = EnvGet("USERPROFILE") MsgBox (0,"",$sEnvVar) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
JockoDundee Posted December 29, 2020 Share Posted December 29, 2020 MsgBox (0,"",@MyDocumentsDir) ronen1n 1 Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
ronen1n Posted December 31, 2020 Author Share 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 Link to comment Share on other sites More sharing options...
GokAy Posted December 31, 2020 Share Posted December 31, 2020 @MyDocumentsDir & "\OneMoreFolder" By the way, yellow can't be read on white background. Link to comment Share on other sites More sharing options...
ronen1n Posted December 31, 2020 Author Share 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 Link to comment Share on other sites More sharing options...
GokAy Posted December 31, 2020 Share 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 Link to comment Share on other sites More sharing options...
ronen1n Posted December 31, 2020 Author Share 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? Link to comment Share on other sites More sharing options...
GokAy Posted January 1, 2021 Share Posted January 1, 2021 (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, 2021 by GokAy Link to comment Share on other sites More sharing options...
JockoDundee Posted January 1, 2021 Share Posted January 1, 2021 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. ronen1n 1 Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
GokAy Posted January 1, 2021 Share Posted January 1, 2021 2 minutes ago, JockoDundee said: No need for the trailing \ in the destination. You don't? The example in the document uses it.. Link to comment Share on other sites More sharing options...
ronen1n Posted January 1, 2021 Author Share Posted January 1, 2021 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? Link to comment Share on other sites More sharing options...
GokAy Posted January 1, 2021 Share Posted January 1, 2021 (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, 2021 by GokAy ronen1n 1 Link to comment Share on other sites More sharing options...
ronen1n Posted January 1, 2021 Author Share Posted January 1, 2021 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 Link to comment Share on other sites More sharing options...
JockoDundee Posted January 1, 2021 Share Posted January 1, 2021 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... Link to comment Share on other sites More sharing options...
ronen1n Posted January 1, 2021 Author Share Posted January 1, 2021 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 GokAy 1 Link to comment Share on other sites More sharing options...
GokAy Posted January 1, 2021 Share Posted January 1, 2021 Thanks for the clarification. Link to comment Share on other sites More sharing options...
JockoDundee Posted January 1, 2021 Share Posted January 1, 2021 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... Link to comment Share on other sites More sharing options...
pixelsearch Posted January 1, 2021 Share Posted January 1, 2021 (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, 2021 by pixelsearch some changes in explanations, depending on the presence (or not) of the 3rd parameter to overwrite GokAy 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now