Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
use QM function to load and modify files of type .psl
#1
Hello everyone , I often use a text editor to modify the .psl file. Can I achieve my purpose using the QM function? I hope someone can provide some help, thanks in advance.

Example:
The following command is in the abc.psl file, I want to change it to the bottom code.

Code:
Copy      Help
select disk 0
select partition 0

vd_store_options
    pwde = "c"

vd_store /path = "C:/" /name = "c"

Code:
Copy      Help
select disk 0
select partition 1

vd_store_options
    pwde = "d"

vd_store /path = "e:/" /name = "f"


Attached Files Image(s)
   

.zip   abc.psl.zip (Size: 228 bytes / Downloads: 319)
#2
this will get you started you should be able to finish the rest

Code:
Copy      Help
str s.getfile("$desktop$\abc.psl\abc.psl");; load the file into a string so you can work with it
s.findreplace("select partition 0" "select partition 1")
;the first set of quotes in findreplace are what to find the second are what to replace with
;s.findreplace("" "");;;uncomment and make changes to findreplace
;s.findreplace("" "");;;uncomment and make changes to findreplace
out s
;when done editing
;s.setfile("$desktop$\abc.psl\abc.psl");; uncomment when you want to save
#3
Double quotes will cause errors

Macro Macro2
Code:
Copy      Help
str s.getfile("$desktop$\abc.psl");; load the file into a string so you can work with it
s.findreplace("select partition 0" "select partition 1")
;the first set of quotes in findreplace are what to find the second are what to replace with
s.findreplace("pwde = "c"" "pwde = "d"");;;uncomment and make changes to findreplace
s.findreplace("/path = "C:/"" "/path = "e:/"");;;uncomment and make changes to findreplace
s.findreplace("/name = "c"" "/name = "f"");;;uncomment and make changes to findreplace
out s
;when done editing
s.setfile("$desktop$\abc.psl");; uncomment when you want to save


Attached Files Image(s)
   
#4
use single quotes inside of double quotes to represent double quotes then code will work
Code:
Copy      Help
s.findreplace("pwde = ''c''" "pwde = ''d''");;

read here for more info
http://www.quickmacros.com/help/Language...STANT.html
#5
Thank you  Heart

I feel that changing the double quotes to single quotes is a bit inconvenient to operate.
#6
In almost all programming languages this is done in one form or another . Burn this to memory very important to remember
this rule applies to strings
#7
thanks for your reminder  Heart

@kevin I have a problem, I want to use a variable, but I can't run successfully.   Huh


Macro Macro3
Code:
Copy      Help
str s.getfile("$desktop$\abc.psl");; load the file into a string so you can work with it
int pt=2
str pt2=F"select partition {pt}"
s.findreplace(F"select partition 0" ''{pt2}'')
out s
;s.setfile("$desktop$\abc.psl");; uncomment when you want to save
#8
I created an input box to receive the variable, but the replacement function does not run successfully.   Huh

I hope someone can help me point out the mistake, thank you very much.

Macro Macro3
Code:
Copy      Help
str pt
inp pt
str s.getfile("$desktop$\abc.psl");; load the file into a string so you can work with it
str pt2=F"select partition {pt}"
out pt2
s.findreplace(F"select partition 0" "{pt2}")
;out s
s.setfile("$desktop$\abca.psl");; uncomment when you want to save
#9
Code:
Copy      Help
str pt
inp pt
str s.getfile("$desktop$\abc.psl");; load the file into a string so you can work with it
str pt2=F"select partition {pt}"
;out pt2
s.findreplace("select partition 0" F"{pt2}")
out s
s.setfile("$desktop$\abca.psl");; uncomment when you want to save
#10
Thank you very much for your help   Heart Heart Heart
#11
How to save the modified file as a new file through the save dialog? I tried many times and could not succeed


Macro Macro2
Code:
Copy      Help
str s1
if OpenSaveDialog(0 s1 "psl files[]*.psl")
,;out s1
,str pt
,inp pt
,str s.getfile(s1);; load the file into a string so you can work with it
,
,s.findreplace("select partition" F"select partition {pt}")
,;out s
,;s.setfile("$desktop$\abca.psl")
,OpenSaveDialog(1 s1 "psl files[]*.psl")
#12
the OpenSaveDialog function doesn't actually open or save a file. It's just a gui that allows a choice and returns that choice as a string. You still need to use getfile to open and setfile to save it.

Code:
Copy      Help
str s1
if OpenSaveDialog(0 s1 "psl files[]*.psl")
,;out s1
,str pt
,inp pt
,str s.getfile(s1);; load the file into a string so you can work with it
,
,s.findreplace("select partition" F"select partition {pt}")
,out s
,OpenSaveDialog(1 s1 "psl files[]*.psl")
,s.setfile(s1)
#13
If there are multiple .psl files on my computer desktop, what should I do with the following code? Note: Add _edit after the modified file name. Can you help me anymore? Thank you


Macro Macro4
Code:
Copy      Help
str s.getfile("$desktop$\abc.psl")

s.findreplace("select partition 0" "select partition 1")

s.setfile(F"$desktop$\abc_edit.psl")
#14
not sure what your trying to do but this is all wrong
s.setfile(F"$desktop$\abc_edit.psl")
there is no need for F parameter there
i think your asking how to edit more than 1 file at a time if so

this would be easiest way for you


Code:
Copy      Help
str s1
ARRAY(str) a; int i
if OpenSaveDialog(0 0 "" "" 0 "" 0 a)  ;;use array so can select multiple files to make changes to
,for(i 0 a.len) 
,,s1.getfile(a[i])l;; loads each file selected
,,s1.findreplace("select partition 0" "select partition 1")
,,out s1;; use this first to make sure your code is correct
,,;s.setfile(a[i])then uncomment this  to save change made



i just noticed that there was an error in previous code  you were trying
str s1
if OpenSaveDialog(0 s1 "psl files[]*.psl")
,;out s1
,str pt
,inp pt
,str s.getfile(s1);; load the file into a string so you can work with it
,
,s.findreplace("select partition" F"select partition {pt}")<--------------------- this line is incorrect first part of findreplace should be "select partition 0"
,out s
,OpenSaveDialog(1 s1 "psl files[]*.psl")
,s.setfile(s1)
otherwise your would end up with this
select partition 1 0 being saved
#15
The above code error, I just found out, thank you for your reminder

I need to process all *.psl files on the desktop, and finally add the suffix _edit after their respective file names. I don't want to overwrite the original file, because sometimes the original file is needed.
#16
need to enumerate the desktop then using dir
keeps original files untouched makes new file with appended name for  example   changes abc.psl to abc_edit.psl


Code:
Copy      Help
Dir d
foreach(d "$Desktop$\*.psl" FE_Dir 4)
,str path=d.FullPath
,str filename=d.FileName
,out filename
,out path
,_s.getfile(path)
,_s.findreplace("select partition 0" "select partition 1")
,filename.findreplace(".psl" "_edit.psl")
,_s.setfile(filename)
#17
Successful run !!! 

Thank you very much, Above programming knowledge, I need a few days to digest, absorb

At the moment, I will only modify the existing code, it is still difficult to write.

Getting started with programming, you gave me too much help, thank you again Heart
#18
That basically  finds all .psl on the desktop or in any subfolder on the desktop loads each files modifies the 1 line then saves the file with the new name leaving  original files untouched

wait need to update that
#19
If the original file has a suffix _edit, it cannot be processed   Big Grin

eg: abc_edit.psl

I want to add Four functions based on the above code. Can you help me? 

This is just a test, I want to see the power of QM programming.  Thanks in advance  Smile

1. Open this post on the forum and download 4files.zip to the desktop (Retrieve the 4files.zip field in the web page, if it exists, then download it)

2. Unzip the 4files.zip file

3. Process the *.psl file in the 4files folder (already OK)

4. Compress the file with the suffix _edit into a new file 4filez_edit.zip

5.Send the 4filez_edit.zip file to the email, for example abc@abc.com


Attached Files
.zip   4files.zip (Size: 852 bytes / Downloads: 329)
#20
here is corrected posts from above that got accidently deleted
will prevent renaming of files that already have the _edit.psl suffix
if you dont file name will keep changing for example from abc.psl to abc_edit.psl to abc_edit_edit.psl ect. ect..
Code:
Copy      Help
Dir d
foreach(d "$Desktop$\*.psl" FE_Dir 4)
,str path=d.FullPath
,str filename=d.FileName
,str s
,_s.getfile(path)
,_s.findreplace("select partition 0" "select partition 1")
,if(find(filename "_edit.psl")<0)
,,filename.findreplace(".psl" "_edit.psl")
,_s.setfile(filename)

i would not name the original file names _edit.psl
#21
I feel that renaming is more difficult.
#22
Sorry i should explain differently renaming  original file names  after editing is fine.  So abc.psl remains  and new file abc_edit.psl is created.  I meant don't  rename before editing.

As far as the other  4 things  have a look at
Intgetfile  or other functions to download the file search forum for examples 
Zip
Need to unzip after downloading 
You  already should  know how to process and edit them. After  editing zip will be used again
Then email  all can be found  lots of examples  on the forum  and in qm help
#23
I can finish 2 3 4 5

But the first one, I don't know how to write code Confused
#24
here are two ways
downloads and unzips on desktop both show a progress bar but you won't really see it file is to small


Code:
Copy      Help
str localfile="$Desktop$\4files.zip"
IntGetFile("http://www.quickmacros.com/forum/attachment.php?aid=864" localfile 16 0 1)
zip- localfile "$Desktop$\4files\" 0


Code:
Copy      Help
str localfile="$Desktop$\4files.zip"
Http h.Connect("www.quickmacros.com")
h.SetProgressDialog(1 "Downloading")
h.Get("forum/attachment.php?aid=864" localfile 16)
zip- localfile "$Desktop$\4files\" 0
#25
Thank you very much, the code runs successfully.  Smile

But there is a problem. If I re-upload 4files.zip, I can't download the file. Can I download it by retrieving the elements in the webpage?

How to hide the download link? As shown below


Attached Files Image(s)
   
#26
don't remove the attachment if you change it. Click the choose file button select the new file then click update attachment button.THat way file attachment number remains the same the file will be the new file but can still be downloaded using the same link.
#27
I know this way of updating files Smile

I want to know what function can be used to retrieve the link field, so that the download link will remain in effect as long as the file name is unchanged.
#28
search the forum plenty of topics about it

look in qm system folder - HtmlDoc also
#29
HtmlDoc.FindHtmlElement

I found this function, but I don't know how to use it, no sample code
#30
@kevin
Hello, I have a problem, can you help me? thanks Smile

Macro Macro3
Code:
Copy      Help
str s.getfile("$desktop$\test.txt")
;
;If the test.txt file contains sss, delete the line it is in, and then add 003 ddd to the line it is in.
out s

s.setfile("$desktop$\test+.txt")


Attached Files
.txt   test.txt (Size: 34 bytes / Downloads: 233)


Forum Jump:


Users browsing this thread: 1 Guest(s)