aaronk Well-Known Member Licensed User Longtime User Jun 17, 2018 #1 Hi, I am copying a file from the DefaultExternal directory to the DirInternal directory. I am checking and copying the file like: Code: Copy If File.Exists(rp.GetSafeDirDefaultExternal(""), "myFile.db") = True Then File.Copy(rp.GetSafeDirDefaultExternal(""),"MyFile.db",File.DirInternal,"myFile.db") End If I am running the above code when the app first opens. (from the Starter Service - Service_Create) At a later time, I am deleting the file in DefaultExternal directory, so the above code won't run next time the app runs. If the code at a later time doesn't run to delete the file then next time the user opens the app, the file will still exist and it will run the above code again. The question I have is, if the file still exists in the defaultExternal and I was to copy the file again (as the code above) would it detect that the file already exists in the new location and not copy or would it still copy the file and replace it ?
Hi, I am copying a file from the DefaultExternal directory to the DirInternal directory. I am checking and copying the file like: Code: Copy If File.Exists(rp.GetSafeDirDefaultExternal(""), "myFile.db") = True Then File.Copy(rp.GetSafeDirDefaultExternal(""),"MyFile.db",File.DirInternal,"myFile.db") End If I am running the above code when the app first opens. (from the Starter Service - Service_Create) At a later time, I am deleting the file in DefaultExternal directory, so the above code won't run next time the app runs. If the code at a later time doesn't run to delete the file then next time the user opens the app, the file will still exist and it will run the above code again. The question I have is, if the file still exists in the defaultExternal and I was to copy the file again (as the code above) would it detect that the file already exists in the new location and not copy or would it still copy the file and replace it ?
Erel B4X founder Staff member Licensed User Longtime User Jun 17, 2018 #2 Tip: Don't use rp.GetSafeDirDefaultExternal("") multiple times. Set this folder in Service_Create of the starter service and use Starter.SourceFolder from now on (or any other meaningful name). aaronk said: The question I have is, if the file still exists in the defaultExternal and I was to copy the file again (as the code above) would it detect that the file already exists in the new location and not copy or would it still copy the file and replace it ? Click to expand... It doesn't check whether the target file exists. It overwrites it if needed. Upvote 0
Tip: Don't use rp.GetSafeDirDefaultExternal("") multiple times. Set this folder in Service_Create of the starter service and use Starter.SourceFolder from now on (or any other meaningful name). aaronk said: The question I have is, if the file still exists in the defaultExternal and I was to copy the file again (as the code above) would it detect that the file already exists in the new location and not copy or would it still copy the file and replace it ? Click to expand... It doesn't check whether the target file exists. It overwrites it if needed.
aaronk Well-Known Member Licensed User Longtime User Jun 17, 2018 #3 Erel said: Tip: Don't use rp.GetSafeDirDefaultExternal("") multiple times. Set this folder in Service_Create of the starter service and use Starter.SourceFolder from now on (or any other meaningful name). Click to expand... Is this the correct way? Starter: Code: Copy Sub Process_Globals 'These global variables will be declared once when the application starts. 'These variables can be accessed from all modules. Dim rp As RuntimePermissions Dim SourceFolder As String End Sub Sub Service_Create SourceFolder = rp.GetSafeDirDefaultExternal("") End Sub Main (or another module): Code: Copy If File.Exists(Starter.SourceFolder, "MyFile.db") = True Then File.Copy(Starter.SourceFolder,"MyFile.db",File.DirInternal,"MyFile.db") End If Upvote 0
Erel said: Tip: Don't use rp.GetSafeDirDefaultExternal("") multiple times. Set this folder in Service_Create of the starter service and use Starter.SourceFolder from now on (or any other meaningful name). Click to expand... Is this the correct way? Starter: Code: Copy Sub Process_Globals 'These global variables will be declared once when the application starts. 'These variables can be accessed from all modules. Dim rp As RuntimePermissions Dim SourceFolder As String End Sub Sub Service_Create SourceFolder = rp.GetSafeDirDefaultExternal("") End Sub Main (or another module): Code: Copy If File.Exists(Starter.SourceFolder, "MyFile.db") = True Then File.Copy(Starter.SourceFolder,"MyFile.db",File.DirInternal,"MyFile.db") End If
Erel B4X founder Staff member Licensed User Longtime User Jun 17, 2018 #4 Yes. Though you should never use Dim in Process_Globals. Use either Private or Public. Public in this case. Upvote 0
Yes. Though you should never use Dim in Process_Globals. Use either Private or Public. Public in this case.