Page 1 of 1 1
Topic Options
#173906 - 07/02/14 03:33 PM Get filename
Duvander Offline
Fresh Scripter

Registered: 05/11/07
Posts: 27
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?

Top
#173908 - 07/02/14 03:37 PM Re: Get filename [Re: Duvander]
Mart Moderator Offline
KiX Supporter
*****

Registered: 02/03/27
Posts: 4600
Loc: The Netherlands
The DriPlus() UDF might be an option.
DirPlus() - a recursive dir tool
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#173928 - 07/02/14 11:14 PM Re: Get filename [Re: Mart]
Duvander Offline
Fresh Scripter

Registered: 05/11/07
Posts: 27
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

Top
#173930 - 07/02/15 01:16 AM Re: Get filename [Re: Duvander]
Witto Offline
MM club member
*****

Registered: 04/09/29
Posts: 1828
Loc: Belgium
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

Top
#173937 - 07/02/15 01:28 PM Re: Get filename [Re: Witto]
Bryce Offline
KiX Supporter
*****

Registered: 00/02/29
Posts: 3164
Loc: Houston TX
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.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Chris S., Glenn Barnas, ShaneEP, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Shawn) and 90 anonymous users online.
Newest Members
B1GHawkeyes, GeoHamm, register, Marcus_Dunne, stuvwx656262
17397 Registered Users

Generated in 0.253 seconds in which 0.169 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org