Duvander
(Fresh Scripter)
2007-02-14 03:33 PM
Get filename

Hi

The path to the file is always the same but the filename can vary.
Example:Path is always "H:\foldername\" and the filename is FILExx.cmd (where xx is random)
I want to run this file if it exist.

IF EXIST("H:\foldername\FILE*.cmd") ;Works ok
RUN "H:\foldername\FILE*.cmd" ;Can't run a file with an asterix (*) in the path
ENDIF

So how can I determine what the hole filename is?


Mart
(KiX Supporter)
2007-02-14 03:37 PM
Re: Get filename

The DriPlus() UDF might be an option.
DirPlus() - a recursive dir tool


Duvander
(Fresh Scripter)
2007-02-14 11:14 PM
Re: Get filename

Thanks, but the UDF was very long (advanced) for this. Later i found the UDF DIRLIST() and I modified that one a little.

IF EXIST("H:\foldername\FILE*.cmd")
DIRLIST("H:\foldername\FILE*.cmd")
SHELL "H:\foldername\" + $searchedfile
ENDIF

FUNCTION DIRLIST($directoryname)
DIM $filename, $counter
DIM $filelist[1]
$counter=1
$filename=DIR($directoryname)
WHILE $filename<>"" AND @ERROR=0
REDIM PRESERVE $filelist[$counter]
$searchedfile = $filename
$filelist[($counter-1)]=$filename
$counter=$counter+1
$filename=DIR("")
LOOP
ENDFUNCTION


Witto
(MM club member)
2007-02-15 01:16 AM
Re: Get filename

Too advanced or too long? Bryce did the job. You just have to know what you put in and what it returns.
Do not forget to add the DirPlus() UDF
 Code:
If NOT @LOGONMODE
	Break On
Else
	Break Off
EndIf
Dim $RC

$RC = SetOption("Explicit", "On")
$RC = SetOption("NoMacrosInStrings", "On")
$RC = SetOption("NoVarsInStrings", "On")
$RC = SetOption("WrapAtEOL", "On")

Dim $Path, $Directory, $Item
$Path = "H:\foldername\"
$Directory = DirPlus($Path)
For Each $Item in $Directory
	If InStr($Item, $Path + "File") AND Right($Item,3) = "CMD"
		; Do stuff here
	EndIf
Next


Bryce
(KiX Supporter)
2007-02-15 01:28 PM
Re: Get filename

well.... DIRPlus() is the Swiss Army knife of directory UDF's \:\)

$Directory = DirPlus($Path,'/a-d /f cmd /m file')

will only return a list of "*.cmd" files that have the word "file" in them.