Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to add index to folder name?
#1
Hi,
I have multiple arbitrarily named folders such as
c:$Desktop$\TEST\fwdpsd
c:$Desktop$\TEST\asde
c:$Desktop$\TEST\dewd3sceded
c:$Desktop$\TEST\afefew
and I want to add the number i to the folder name
at the beginning of each folder following the alphabetical order.

For the example above, the folders above should be renamed to
c:$Desktop$\TEST\1_afefew
c:$Desktop$\TEST\2_asde
c:$Desktop$\TEST\3_dewd3sceded
c:$Desktop$\TEST\4_fwdpsd
Code:
Copy      Help
I've tried the following:
int i j=5
for(i 1 j)
,out i
,ren F"$Desktop$\TEST\*.*" F"$Desktop$\TEST\{i}_*.*"
but unfortunately it did not work.

Later I want also to access the folder by only using the numbers, such as
Code:
Copy      Help
int i j=5
for(i 1 j)
,out i
,str fileName.expandpath(F"$Desktop$\TEST\{i}_*.*\{i}")
,run "Notepad.exe" """""" 0x2800 win("Untitled - Notepad" "Notepad")
,'A{fa}            ;; Alt
,wait(5 win("Save As" "#32770"))
,'(fileName) Y
,'A{fx}

I wonder if someone could tell me the right syntax so that these commands does what I expect.

Thanks in advance for your help
Emerson
#2
Macro Macro1943
Code:
Copy      Help
out
out "----- rename -----"

int i
ARRAY(str) a
GetFilesInFolder a "$desktop$\test" "" 1
a.sort(8)
for i 0 a.len
,str& s1=a[i]
,str s2 s3
,s2=s1
,s2.insert(F"{i+1}_" findcr(s2 '\')+1)
,out s2
,;ren s1 s2

Macro Macro1942
Code:
Copy      Help
out
out "----- access -----"

int i
str s2 s3
s2.expandpath("$desktop$\test\")
for i 0 1000000000
,lpstr filename=dir(F"{s2}{i+1}_*" 1); if(!filename) break
,s3=F"{s2}{filename}"
,out s3


Forum Jump:


Users browsing this thread: 1 Guest(s)