Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Enumerate hard disks, exclude partitions
#1
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.  Smile

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
#2
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

info.bat
Code:
Copy      Help
@echo off

(echo list disk
echo sel disk 0
echo list part
echo list disk
echo sel disk 1
echo list part)>a.txt
diskpart /s a.txt

pause

My idea: get the information in the command line, output it to QM, and then retrieve the fields of the hard disk and the fields of the partition.   Exclamation


Attached Files Image(s)
   
#3
Need to put the commands  in a text  file then can run using runconsole2. Give me a couple minutes will post  qm code

make a text file put in this


list disk
sel disk 0
list part
list disk
sel disk 1
list part
exit

then for qm code use this
Code:
Copy      Help
_s.expandpath("$desktop$\diskpartinfo.txt")
RunConsole2 F"cmd.exe /C  diskpart /s ''{_s}''"
#4
Thank you for your help,

The first question has been resolved, 

how to retrieve fields? This is for me, I only understand the principle, do not know how to write the code, 

what kind of knowledge do I need to learn? Confused   Can you write an example for me?
#5
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
Code:
Copy      Help
_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]
#6
Partition information of two hard disks, one in the front and one in the back, how to judge?

How to display their information in a dialog: for example:

You currently have ___ hard drive
The first hard drive has ___ partitions
The second hard drive has ___ partitions

I feel very complicated, is there a simpler way to achieve my purpose? Huh
#7
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
Code:
Copy      Help
_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)" 0 0) >=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." 0 1)
,if ss!="Disk 1 is now the selected disk."    
,,if(findrx(ss "Partition(?=\s\d+)" t 0 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=find(ss "Disk 1 is now the selected disk." 0 1)
,,tt=0
,,if(findrx(ss "Partition(?=\s\d+)" t 0 0)>=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
#8
Judge error

The listpart command can be used only after selecting the hard disk.

————————————————————————————————————

list disk
sel disk 0
list part
sel disk 1
list part
exit

The following is assuming that there are four hard drives.

——————————————————————

sel disk 0
list part
sel disk 1
list part
sel disk 2
list part

sel disk 3
list part

exit

I feel that this little program needs a lot of perfection.

Sometimes I feel that I haven’t done it manually yet.   Big Grin


Attached Files Image(s)
   
#9
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
#10
Still partition recognition error


Attached Files Image(s)
   
#11
try this

Code:
Copy      Help
_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)" 0 0) >=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." 0 1)
,if ss!="Disk 1 is now the selected disk."
,,if(findrx(ss "Partition(?=\s\d+)" t 0 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." 0 1)
,,tttt=1
,if tttt=1
,,if(findrx(ss "Partition(?=\s\d+)" t 0 0)>=0)
,,,partitionlist2+ ss
,,,tttt+1
,if tttt >1
,,if(findrx(ss "Partition(?=\s\d+)" t 0 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
i uncommented some outs so we can see what its showing. sorry had to edit code it didn't paste it all
#12
Repeated calculation

hd0  has 5 part
hd1 has 3 part


Attached Files Image(s)
   
#13
that is very odd didn't do that on my two computers
#14
This is the result of cmd processing


Attached Files Image(s)
   
#15
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

Function Function166
Code:
Copy      Help
_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)" 0 0) >=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." 0 1)
,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." 0 1)
,,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
#16
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.


Macro Macro2
Code:
Copy      Help
_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)" 0 0) >=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." 0 1)
,if ss!="Disk 1 is now the selected disk."
,,if(findrx(ss "Partition(?=\s\d+)" t 0 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." 0 1)
,,tttt=1
,if tttt=1
,,if(findrx(ss "Partition(?=\s\d+)" t 0 0)>=0)
,,,partitionlist2+ ss
,,,tttt+1
,if tttt >1
,,if(findrx(ss "Partition(?=\s\d+)" t 0 0)>=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


str dd=
F
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;3 Static 0x54000000 0x0 12 12 198 82 "{s1}"
;4 Edit 0x54030080 0x200 161 100 38 14 ""
;5 Static 0x54000000 0x0 104 101 52 13 "excluded part:"
;6 Static 0x54000000 0x4 12 101 38 14 "select HD:"
;7 Edit 0x54030080 0x204 54 100 38 14 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040700 "*" "" "" ""

str controls = "4 7"
str e4 e7
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1


Attached Files Image(s)
   
#17
first things first let's get this other part finished then can work on dialog
#18
Still wrong,


Attached Files Image(s)
   
#19
i'm only on a pc now that has 1 hd but try changing this
change line 43 to this

if(findrx(ss "Partition(?=\s\d+)" 0 0)>=0)
that should fix the second partition list mistake hopefully lol
#20
Still wrong


Attached Files Image(s)
   
#21
ok gimme a few minutes will redo code completely.

ok hopefully this works for ya

Code:
Copy      Help
_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)" 0 0) >=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+)" 0 0)>=0)
,,,if tt=0
,,,,partitionlist1+ a[i]
,,,,tt+1
,,,else
,,,,partitionlist1 + "[]"
,,,,partitionlist1 +a[i]
,,,,tt+1
,else
,,if(findrx(a[i] "Partition(?=\s\d+)" 0 0)>=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
#22
Great, OK   Heart

Text control can only display one line  Huh

2.for example, if I select disk 1  partition  1, and press the Enter

3. Finally, copy the test.txt file on the desktop to the partition 2 3 4 5



Macro Macro2
Code:
Copy      Help
_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)" 0 0) >=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+)" 0 0)>=0)
,,,if tt=0
,,,,partitionlist1+ a[i]
,,,,tt+1
,,,else
,,,,partitionlist1 + "[]"
,,,,partitionlist1 +a[i]
,,,,tt+1
,else
,,if(findrx(a[i] "Partition(?=\s\d+)" 0 0)>=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


str dd=
F
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;3 Static 0x54000000 0x0 12 12 198 82 "{s1}"
;4 Edit 0x54030080 0x200 161 100 38 14 ""
;5 Static 0x54000000 0x0 104 101 52 13 "excluded part:"
;6 Static 0x54000000 0x4 12 101 38 14 "select HD:"
;7 Edit 0x54030080 0x204 54 100 38 14 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040700 "*" "" "" ""

str controls = "4 7"
str e4 e7
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1


Attached Files Image(s)
   
#23
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

Code:
Copy      Help
_s.expandpath("$desktop$\diskpartinfo.txt")
str s cl=F"cmd.exe /C diskpart /s ''{_s}''"
RunConsole2 cl s
s.trim
int i tt ttt tttt tset
str 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
,if(findrx(a[i] "Disk(?=\s\d*\s+Online)" 0 0) >=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+)" 0 0)>=0)
,,,if tt=0
,,,,partitionlist1+ a[i]
,,,,tt+1
,,,else
,,,,partitionlist1 + "[]"
,,,,partitionlist1 +a[i]
,,,,tt+1
,else
,,if(findrx(a[i] "Partition(?=\s\d+)" 0 0)>=0)
,,,if tttt=0
,,,,partitionlist2+ a[i]
,,,,tttt+1
,,,else
,,,,partitionlist2 + "[]"
,,,,partitionlist2 +a[i]
,,,,tttt+1
int disknum= numlines(disklist)
int part1num= numlines(partitionlist1)
int part2num= numlines(partitionlist2)

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;3 Static 0x54000000 0x0 12 12 198 82 ""
;4 Edit 0x54030080 0x200 161 100 38 14 ""
;5 Static 0x54000000 0x0 104 101 52 13 "excluded part:"
;6 Static 0x54000000 0x4 12 101 38 14 "select HD:"
;7 Edit 0x54030080 0x204 54 100 38 14 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040700 "*" "" "" ""

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

if(!ShowDialog(dd &sub.DlgProc &controls)) ret
if(!empty(e4))
,out e4
if(!empty(e7))    
,out e7

#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

also showed how to get the values of the two edits when you click ok
#24
The code is much more concise, only the third step is left.

Copy the command I know, but set the condition, loop copy, I can't write the code   Smile
#25
The above code, under the Chinese operating system, can not get any information  Huh

Chinese command line information in the following file


Attached Files
.zip   china cmd info.zip (Size: 540 bytes / Downloads: 286)
#26
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.
#27
this will work for the text file(china cmd info.txt) at least on my pc it does. 

Code:
Copy      Help
str s.getfile("$desktop$\china cmd info.txt")
s.trim
s.ConvertEncoding(936 _unicode)
;out s
int i tt ttt tttt tset
str 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
,if(findrx(a[i] "磁盘(?=\s\d*\s+联机)" 0 0) >=0)
,,if ttt=0
,,,disklist+ a[i]
,,,ttt+1
,,else
,,,disklist+"[]"
,,,disklist+ a[i]
,,,ttt+1
,if(a[i]="磁盘 0 现在是所选磁盘。")
,,tset=!tset
,if(a[i]="磁盘 1 现在是所选磁盘。")
,,tset=!tset
,if tset
,,if(findrx(a[i] "分区(?=\s+\d+)" 0 0)>=0)
,,,if tt=0
,,,,partitionlist1+ a[i]
,,,,tt+1
,,,else
,,,,partitionlist1 + "[]"
,,,,partitionlist1 +a[i]
,,,,tt+1
,else
,,if(findrx(a[i] "分区(?=\s+\d+)" 0 0)>=0)
,,,if tttt=0
,,,,partitionlist2+ a[i]
,,,,tttt+1
,,,else
,,,,partitionlist2 + "[]"
,,,,partitionlist2 +a[i]
,,,,tttt+1
int disknum= numlines(disklist)
int part1num= numlines(partitionlist1)
int part2num= numlines(partitionlist2)
out disknum
out part1num
out part2num

I don't know if it will work for results from RunConsole2

need to see what the output looks like.
after line 4 in original function
Code:
Copy      Help
s.trim

add new line

Code:
Copy      Help
out s
 and copy output and paste here so can see what coding string s is in
#28
Thank you very much for your help, the test is successful.

I feel that there may be a function to directly obtain the number of hard disks and the number of partitions.

Using the batch +diskpart method feels a bit complicated
#29
should not be using a batch file at all
#30
echo list disk
echo sel disk 0
echo list part
echo list disk
echo sel disk 1
echo list part


The number of hard disks above is directly determined.

The actual situation may be multiple hard drives

They should be selected according to the list disk and show the partitions they contain.

This needs to break up the command line and write the QM code separately?

I personally feel that sometimes there are some small requirements, if I want to achieve automation, I need too much programming level.


Forum Jump:


Users browsing this thread: 1 Guest(s)