Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Check if certain file/folder/Ftp file/program exist
#1
Hi,


What are the most efficient ways to confirm that certain elementss exist (and be able to ret an error if not). The point of all this is to ensure that on run, the macro can throw up an error and open configuration panel if certain elements needed in the macro don't exist/no longer exist (e.g., if user entered incorrect settings, or otherwise does something to change the computer setup like add a new drive that changes drive letters). If it matters, all elements are stored in strings.

str testdir = "f:\test\"
(check if a directory exists)

str testfile = "f:\test\file.txt"
(check if a file exists)

str testftp = "''ftp.server.com'' ''myuser'' ''mypassw0rd''"
(check if it can connect to ftp successfully. As it is, the macro ends on wrong ftp password, username or address - so I need to check connection and throw error well before it gets to that point -- which is at the end of the whole macro process, after much user entry, lengthy file conversions, archiving etc)

Thanks!

S
#2
if(!dir(testdir, 1)) end "does not exist"

if(!dir(testfile)) end "does not exist"

Ftp f.Connect(...); f.Disconnect ;;place this at the beginning. The macro will end with error if cannot connect.
#3
Thanks for you help.

So...on failed Ftp f.Connect(...), is there a way to not have the macro end but just return on error?

(I have tried to call ftp routine from macro as both another macro and as a function with no luck returning back to the main macro)
#4
Ftp f.Connect(...)
err ret
f.Disconnect
#5
Appreciated.

Another 'exists' question:

How about checking the existence of a registered program (e.g., one that is run from the macro without a path).

In this case, audio editor Sound Forge v8 is run from the macro like so:

str editor = "forge80.exe"
run editor
If the audio software is upgraded to SF v9, the exe will be "forge90.exe" and the macro won't work. Again, I want to check that if the user config is set to forge80, I can test that it exists before getting into the process.

Thanks.

s
#6
Function GetInstalledProgramPath
Code:
Copy      Help
;/
function# $exename str&path

;Gets full path of a program that registers itself in 'App Paths' registry key when installing.
;Returns 1 if found, 0 if not.

;exename - program filename. Can contain wildcard characters. For example, "forge??.exe" would find "forge80.exe", "forge90.exe" etc.
;path - str variable that receives full path of the program file.

;EXAMPLE
;str path
;if(GetInstalledProgramPath("qm.exe" path))
,;out path
;else
,;out "not installed"


str ap="SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths"
ARRAY(str) a; int i
RegGetSubkeys a ap HKEY_LOCAL_MACHINE
for i 0 a.len
,if(matchw(a[i] exename 1))
,,ret(rget(path "" _s.from(ap "\" a[i]) HKEY_LOCAL_MACHINE)>1)
path.all
#7
Fantastic...a beautiful thing.


Forum Jump:


Users browsing this thread: 1 Guest(s)