Posts: 1,006
Threads: 330
Joined: Mar 2007
Having trouble with this
In a folder there are two files
one with an extension (.oly) and the identical one without, e.g.
\101 Week 24 T2
\101 Week 24 T2.oly
The 101 part is variable so let's say it's
C:\*24 T2
C:\*24 T2.oly
I want to add the extension .ches to the ones without an extension
I have tried
ren* "C:\*24*air" "C:\*24*air.ches"
but it doesn't like the syntax
also I tried getting string of filepath, getting its length and adding the .ches as a string using the insert command
but it doesn't seem to like * in the syntax
Additional questions:
is it possible to use Regex expressions in filepath names
is there a way to append to the end of a string without knowing it's length ahead of time?
Thanks,
Stuart
Posts: 12,147
Threads: 143
Joined: Dec 2002
When simple commands with * don't work, remember Enumerate Files dialog.
When using ren*, second argument can be filename without path.
* can be used only in first argument.
Instead of len and insert, use +:
path+".ches"
File commands don't support regular expressions directly.
Posts: 1,006
Threads: 330
Joined: Mar 2007
That's so logical and even better it works too!
Thanks again,
Stuart
Posts: 1,006
Threads: 330
Joined: Mar 2007
Hi,
C:\*24 T2
C:\*24 T2.oly
these two files are in the same folder and only the one that doesn't have the .oly extension should be made into a shortcut in a different folder
However all the "*" or "?" combinations don't seem to distinguish between these two because the quotations just match but don't exclude.
How would I use enumerate files or some other way to match only one of these (without using regex because its a file path, of course)
Thanks so much.
Stuart
Posts: 12,147
Threads: 143
Joined: Dec 2002
;standard enumerate files code
Dir d
foreach(d "C:\*24 T2*" FE_Dir)
,str sPath=d.FileName(1)
,;out sPath
,
,;use for example endi
,if(!sPath.endi(".oly"))
,,out sPath
,
,;or use regular expression
,if(findrx(sPath "^C:\\.*24 T2$")=0)
,,out sPath
;(not tested)
Posts: 12,147
Threads: 143
Joined: Dec 2002
Function EnumFilesRX
;/
function $parentFolder $filenameRX ARRAY(str)&a [flags] ;;flags: 0 files, 1 folders, 2 any, 4 include subfolders, 8 only subfolders, 0x80000 evaluate relative path
;Gets full paths of files that are in parentFolder and whose filenames match regular expression filenameRX.
;Stores them into a.
;Evaluation is case insensitive.
;This function requires QM 2.2.0 or above.
;If used flag 0x80000, evaluated is whole relative path followed by parentFolder and \. That is, it includes subfolder names (assuming that flags 4 or 8 used). If this flag is not used, evaluated is only filename.
;Note: If used flag 0x80000, \ characters in filenameRX must be \\, because whole filenameRX is regular expression.
;EXAMPLE
;ARRAY(str) a; int i
;EnumFilesRX "$system$" "^.*\.exe$" a
;for i 0 a.len
,;out a[i]
a=0
str s.expandpath(parentFolder)
s.dospath(s 1)
if(!s.end("\")) s+"\"
s+"*"
Dir d
foreach(d s FE_Dir flags&0xffff)
,str sPath=d.FileName(1)
,lpstr ss
,if(flags&0x80000) ss=sPath+s.len-1; else ss=d.FileName
,if(findrx(ss filenameRX 0 1)>=0) a[a.redim(-1)]=sPath
Posts: 1,006
Threads: 330
Joined: Mar 2007
Can't wait to try both solutions! Thanks again,
Stuart