I often do the following manually, I think it would be more convenient to use QM, but writing code is a bit difficult for me, I hope someone can help me, thanks in advance.
1. Pop up a dialog box, suggesting that there are a total of N hard disks, asking which hard disk to copy the files to. For example, there are two hard disks in my computer. It will prompt for a total of 2 hard disks. Then, I enter the number 1 and press Enter
2. Then pop up the second dialog box, there are N partitions under the hard disk, ask which partition under the hard disk to exclude, for example, my hard disk 1 has C D E F four partitions, I entered the letter C, and press the Enter
3. Finally, copy the test.txt file on the desktop to the other partition D E F of the hard disk
09-09-2018, 12:41 AM (This post was last modified: 09-09-2018, 01:20 AM by win.)
I use a batch file to get information about the hard disk and partition, but I don't know how to get this information into QM,I hope someone can help me, thanks
this will remove the empty lines and store each line in an array element. then can get info you want out of the array. Each ARRAY element is in this case a[0] a[1] a[2] ect ect
_s.expandpath("$desktop$\diskpartinfo.txt") str s cl=F"cmd.exe /C diskpart /s ''{_s}''" RunConsole2 cl s
s.trim int i str ss ARRAY(str) a=s for(i a.len-1-1-1) ,if a[i].len =0 ,,a.remove(i) for i 0 a.len ,out a[i]
09-09-2018, 05:34 AM (This post was last modified: 09-09-2018, 05:41 AM by Kevin.)
programming is not always simple. there are many factors and many lines that need to be parsed.
just because in our thoughts it's simple doesn't mean it will be in programming
to extract the information you want try this
also change diskpartinfo.txt to
list disk
sel disk 0
list part
list disk
sel disk 1
exit
dont need the second list disk command
_s.expandpath("$desktop$\diskpartinfo.txt") str s cl=F"cmd.exe /C diskpart /s ''{_s}''" RunConsole2 cl s
s.trim int i t tt ttt str ss disklist partitionlist1 partitionlist2 ARRAY(str) a=s for(i a.len-1-1-1) ,if a[i].len =0 ,,a.remove(i) for i 0 a.len ,a[i].trim ,ss=a[i] ,;out ss ,if(findrx(ss "Disk(?=\s\d*\s+Online)"00)>=0) ,,if ttt=0 ,,,disklist+ ss ,,,ttt+1 ,,else ,,,disklist+"[]" ,,,disklist+ ss ,,,ttt+1 ,if ss="Disk 0 is now the selected disk." ,,t=find(ss "Disk 0 is now the selected disk."01) ,if ss!="Disk 1 is now the selected disk." ,,if(findrx(ss "Partition(?=\s\d+)" t 00)>=0) ,,,if tt=0 ,,,,partitionlist1+ ss ,,,,tt+1 ,,,else ,,,,partitionlist1 +"[]" ,,,,partitionlist1 +ss ,,,,tt+1 ,if ss="Disk 1 is now the selected disk." ,,t=find(ss "Disk 1 is now the selected disk."01) ,,tt=0 ,,if(findrx(ss "Partition(?=\s\d+)" t 00)>=0) ,,,if tt=0 ,,,,partitionlist2+ ss ,,,,tt+1 ,,,else ,,,,partitionlist2 +"[]" ,,,,partitionlist2 +ss ,,,,tt+1 ;out disklist int disknum=numlines(disklist) out"You currently have %i hard drives" disknum ;out partitionlist1 int part1num=numlines(partitionlist1) out"The first hard drive has %i partitions" part1num int part2num=numlines(partitionlist2) out"The second hard drive has %i partitions" part2num ;out partitionlist2
09-09-2018, 05:53 AM (This post was last modified: 09-09-2018, 05:54 AM by Kevin.)
i know very well how the cmd code works no explanation needed
was a typo removed wrong line
list disk
sel disk 0
list part
sel disk 1
list part
exit
run again with corrected text file and see what results are
all the information you need is stored in the Array
_s.expandpath("$desktop$\diskpartinfo.txt") str s cl=F"cmd.exe /C diskpart /s ''{_s}''" RunConsole2 cl s
s.trim int i t tt ttt tttt str ss disklist partitionlist1 partitionlist2 ARRAY(str) a=s for(i a.len-1-1-1) ,if a[i].len =0 ,,a.remove(i) for i 0 a.len ,a[i].trim ,ss=a[i] ,;out ss ,if(findrx(ss "Disk(?=\s\d*\s+Online)"00)>=0) ,,if ttt=0 ,,,disklist+ ss ,,,ttt+1 ,,else ,,,disklist+"[]" ,,,disklist+ ss ,,,ttt+1 ,if ss="Disk 0 is now the selected disk." ,,t=find(ss "Disk 0 is now the selected disk."01) ,if ss!="Disk 1 is now the selected disk." ,,if(findrx(ss "Partition(?=\s\d+)" t 00)>=0) ,,,if tt=0 ,,,,partitionlist1+ ss ,,,,tt+1 ,,,else ,,,,partitionlist1 +"[]" ,,,,partitionlist1 +ss ,,,,tt+1 ,if ss="Disk 1 is now the selected disk." ,,t=0 ,,t=find(ss "Disk 1 is now the selected disk."01) ,,tttt=1 ,if tttt=1 ,,if(findrx(ss "Partition(?=\s\d+)" t 00)>=0) ,,,partitionlist2+ ss ,,,tttt+1 ,if tttt >1 ,,if(findrx(ss "Partition(?=\s\d+)" t 00)>=0) ,,,partitionlist2 +"[]" ,,,partitionlist2 +ss ,,,tttt+1 out disklist int disknum=numlines(disklist) out"You currently have %i hard drives" disknum out partitionlist1 int part1num=numlines(partitionlist1) out"The first hard drive has %i partitions" part1num int part2num=numlines(partitionlist2) out"The second hard drive has %i partitions" part2num out partitionlist2
i uncommented some outs so we can see what its showing. sorry had to edit code it didn't paste it all
09-09-2018, 06:32 AM (This post was last modified: 09-09-2018, 06:37 AM by Kevin.)
dam typos getting me tonight yes i know what your results should be
try this i made some typos in previous versions had extra zeros in findrx statements
_s.expandpath("$desktop$\diskpartinfo.txt") str s cl=F"cmd.exe /C diskpart /s ''{_s}''" RunConsole2 cl s
s.trim int i t tt ttt tttt str ss disklist partitionlist1 partitionlist2 ARRAY(str) a=s for(i a.len-1-1-1) ,if a[i].len =0 ,,a.remove(i) for i 0 a.len ,a[i].trim ,ss=a[i] ,;out ss ,if(findrx(ss "Disk(?=\s\d*\s+Online)"00)>=0) ,,if ttt=0 ,,,disklist+ ss ,,,ttt+1 ,,else ,,,disklist+"[]" ,,,disklist+ ss ,,,ttt+1 ,if ss="Disk 0 is now the selected disk." ,,t=find(ss "Disk 0 is now the selected disk."01) ,if ss!="Disk 1 is now the selected disk." ,,if(findrx(ss "Partition(?=\s\d+)" t 0)>=0) ,,,if tt=0 ,,,,partitionlist1+ ss ,,,,tt+1 ,,,else ,,,,partitionlist1 +"[]" ,,,,partitionlist1 +ss ,,,,tt+1 ,if ss="Disk 1 is now the selected disk." ,,t=0 ,,t=find(ss "Disk 1 is now the selected disk."01) ,,tttt=1 ,if tttt=1 ,,if(findrx(ss "Partition(?=\s\d+)" t 0)>=0) ,,,partitionlist2+ ss ,,,tttt+1 ,if tttt >1 ,,if(findrx(ss "Partition(?=\s\d+)" t 0)>=0) ,,,partitionlist2 +"[]" ,,,partitionlist2 +ss ,,,tttt+1 out disklist int disknum=numlines(disklist) out"You currently have %i hard drives" disknum out partitionlist1 int part1num=numlines(partitionlist1) out"The first hard drive has %i partitions" part1num int part2num=numlines(partitionlist2) out"The second hard drive has %i partitions" part2num out partitionlist2
if you want to see the full result just uncomment line 14
I added a dialog, but only one line of text is displayed on the label control. In addition to the third function, I am writing code that is difficult to complete.
_s.expandpath("$desktop$\diskpartinfo.txt") str s cl=F"cmd.exe /C diskpart /s ''{_s}''" RunConsole2 cl s
s.trim int i t tt ttt tttt str ss disklist partitionlist1 partitionlist2 ARRAY(str) a=s for(i a.len-1-1-1) ,if a[i].len =0 ,,a.remove(i) for i 0 a.len ,a[i].trim ,ss=a[i] ,;out ss ,if(findrx(ss "Disk(?=\s\d*\s+Online)"00)>=0) ,,if ttt=0 ,,,disklist+ ss ,,,ttt+1 ,,else ,,,disklist+"[]" ,,,disklist+ ss ,,,ttt+1 ,if ss="Disk 0 is now the selected disk." ,,t=find(ss "Disk 0 is now the selected disk."01) ,if ss!="Disk 1 is now the selected disk." ,,if(findrx(ss "Partition(?=\s\d+)" t 00)>=0) ,,,if tt=0 ,,,,partitionlist1+ ss ,,,,tt+1 ,,,else ,,,,partitionlist1 +"[]" ,,,,partitionlist1 +ss ,,,,tt+1 ,if ss="Disk 1 is now the selected disk." ,,t=0 ,,t=find(ss "Disk 1 is now the selected disk."01) ,,tttt=1 ,if tttt=1 ,,if(findrx(ss "Partition(?=\s\d+)" t 00)>=0) ,,,partitionlist2+ ss ,,,tttt+1 ,if tttt >1 ,,if(findrx(ss "Partition(?=\s\d+)" t 00)>=0) ,,,partitionlist2 +"[]" ,,,partitionlist2 +ss ,,,tttt+1 ;out disklist int disknum=numlines(disklist) int part1num=numlines(partitionlist1) int part2num=numlines(partitionlist2) str s1= F ;You currently have {disknum} hard drives ;The first hard drive has {part1num} partitions ;The second hard drive has {part2num} partitions mes s1
_s.expandpath("$desktop$\diskpartinfo.txt") str s cl=F"cmd.exe /C diskpart /s ''{_s}''" RunConsole2 cl s
s.trim ;out s int i t tt ttt tttt tset str ss disklist partitionlist1 partitionlist2 ARRAY(str) a=s for(i a.len-1-1-1) ,if a[i].len =0 ,,a.remove(i) for i 0 a.len ,a[i].trim ,ss=a[i] ,;out i ,;out ss ,if(findrx(a[i] "Disk(?=\s\d*\s+Online)"00)>=0) ,,if ttt=0 ,,,disklist+ a[i] ,,,ttt+1 ,,else ,,,disklist+"[]" ,,,disklist+ a[i] ,,,ttt+1 ,if(a[i]="Disk 0 is now the selected disk.") ,,tset=!tset ,if(a[i]="Disk 1 is now the selected disk.") ,,tset=!tset ,if tset ,,if(findrx(a[i] "Partition(?=\s\d+)"00)>=0) ,,,if tt=0 ,,,,partitionlist1+ a[i] ,,,,tt+1 ,,,else ,,,,partitionlist1 +"[]" ,,,,partitionlist1 +a[i] ,,,,tt+1 ,else ,,if(findrx(a[i] "Partition(?=\s\d+)"00)>=0) ,,,if tttt=0 ,,,,partitionlist2+ a[i] ,,,,tttt+1 ,,,else ,,,,partitionlist2 +"[]" ,,,,partitionlist2 +a[i] ,,,,tttt+1 out disklist int disknum=numlines(disklist) out"You currently have %i hard drives" disknum out partitionlist1 int part1num=numlines(partitionlist1) out"The first hard drive has %i partitions" part1num int part2num=numlines(partitionlist2) out"The second hard drive has %i partitions" part2num out partitionlist2
_s.expandpath("$desktop$\diskpartinfo.txt") str s cl=F"cmd.exe /C diskpart /s ''{_s}''" RunConsole2 cl s
s.trim ;out s int i t tt ttt tttt tset str ss disklist partitionlist1 partitionlist2 ARRAY(str) a=s for(i a.len-1-1-1) ,if a[i].len =0 ,,a.remove(i) for i 0 a.len ,a[i].trim ,ss=a[i] ,;out i ,;out ss ,if(findrx(a[i] "Disk(?=\s\d*\s+Online)"00)>=0) ,,if ttt=0 ,,,disklist+ a[i] ,,,ttt+1 ,,else ,,,disklist+"[]" ,,,disklist+ a[i] ,,,ttt+1 ,if(a[i]="Disk 0 is now the selected disk.") ,,tset=!tset ,if(a[i]="Disk 1 is now the selected disk.") ,,tset=!tset ,if tset ,,if(findrx(a[i] "Partition(?=\s\d+)"00)>=0) ,,,if tt=0 ,,,,partitionlist1+ a[i] ,,,,tt+1 ,,,else ,,,,partitionlist1 +"[]" ,,,,partitionlist1 +a[i] ,,,,tt+1 ,else ,,if(findrx(a[i] "Partition(?=\s\d+)"00)>=0) ,,,if tttt=0 ,,,,partitionlist2+ a[i] ,,,,tttt+1 ,,,else ,,,,partitionlist2 +"[]" ,,,,partitionlist2 +a[i] ,,,,tttt+1 ;out disklist int disknum=numlines(disklist) int part1num=numlines(partitionlist1) int part2num=numlines(partitionlist2) str s1= F ;You currently have {disknum} hard drives ;The first hard drive has {part1num} partitions ;The second hard drive has {part2num} partitions mes s1
09-09-2018, 08:06 AM (This post was last modified: 09-09-2018, 08:31 AM by Kevin.)
this fixes dialog static text display really don't need a mes before if your showing same thing in dialog its redundant. also clean up the function some got rid of unused variables
str controls ="3 4 7" str s3 e4 e7
s3= F ;You currently have {disknum} hard drives ;The first hard drive has {part1num} partitions ;The second hard drive has {part2num} partitions
09-09-2018, 04:10 PM (This post was last modified: 09-09-2018, 04:30 PM by Kevin.)
All codes are written in and for English. Qm is made to work in english. Install En-us language pack if you dont have . I can not read or speak chinese, sorry cant help.