Posts: 1,058
Threads: 367
Joined: Oct 2007
Supposed that string Quote:str sf="$17$ 6A...."
corresponds to a Mass Memory folder of a Symbian-S60 phone. Running sf opens folder
Quote:My Computer\Phone Model\Mass memory\Logs
This folder contains .csv files.
I am in need of advice to automate copying these files to a disk folder, for example C:\tmp. It is implied that this task can be operated manually, using explorer commands. Many thanks in advance.
Posts: 12,097
Threads: 142
Joined: Dec 2002
Function CopyFilesFromVirtualFolder
;/
function# str'sourceFolder str'destFolder [str'filesToCopy]
;Copies files from a virtual (or normal) folder to a normal (or virtual) folder.
;Returns the number of copied items (direct children of sourceFolder). Error if fails.
;sourceFolder - source folder pidl string.
;;;To get folder pidl string, Shift+drag and drop it to the QM code editor.
;destFolder - destination folder path.
;;;If folder does not exist, creates, unless destFolder does not contain \ character (eg it is a virtual folder).
;filesToCopy - filename. Use wildcard for multiple files.
;;;Applied only to direct child items.
;;;If omitted or empty, copies all files and subfolders.
;REMARKS
;Not for Windows XP.
;EXAMPLE
;str sourceFolder="$17$ 3A002E803ACCBFB42CDB4C42B0297FE99A87C641260001002500EFBE110000000A5AA837A573D0011C66AFAEC70DD1011C66AFAEC70DD1011400" ;;Desktop (example)
;str destFolder="C:\Test\Sub"
;CopyFilesFromVirtualFolder sourceFolder destFolder "*.csv"
opt noerrorshere
if(_winver<0x600) end "not for Windows XP"
;get IShellItem of the source folder
ITEMIDLIST* pi=PidlFromStr(sourceFolder); if(!pi) end F"{ERR_FAILED}. Possibly invalid sourceFolder"
IShellItem siFolder1
int hr=WINAPIV.SHCreateItemFromIDList(pi IID_IShellItem &siFolder1); CoTaskMemFree pi
if(hr) end F"{ERR_FAILED}. Possibly invalid sourceFolder"
;get IShellItem of the destination folder
if(findc(destFolder '\')>=0 and !FileExists(destFolder 1)) mkdir destFolder
pi=PidlFromStr(destFolder); if(!pi) end F"{ERR_FAILED}. Possibly invalid destFolder"
IShellItem siFolder2
hr=WINAPIV.SHCreateItemFromIDList(pi IID_IShellItem &siFolder2); CoTaskMemFree pi
if(hr) end F"{ERR_FAILED}. Possibly invalid destFolder"
;get IEnumShellItems
IEnumShellItems en
siFolder1.BindToHandler(0 BHID_EnumItems IID_IEnumShellItems &en)
;create IFileOperation
WINAPIV.IFileOperation fo._create(CLSID_FileOperation)
;enumerate items
int R
rep ;;doesn't work: foreach siFolder1 en
,;get child item IShellItem
,IShellItem si=0; en.Next(1 &si &_i); if(!_i) si=0; break
,;copy only matching items
,if filesToCopy.len
,,word* dn; si.GetDisplayName(SIGDN_PARENTRELATIVE &dn)
,,str name.ansi(dn); CoTaskMemFree dn
,,;out name
,,if(!matchw(name filesToCopy 1)) continue
,;add to the 'copy' collection
,fo.CopyItem(si siFolder2 0 0)
,R+1
;now copy
if(R) fo.PerformOperations
ret R
;TODO: options, eg overwrite existing files without asking.
Posts: 1,058
Threads: 367
Joined: Oct 2007
Dear Gintaras,
Many thanks, indeed!
Nevertheless I would like to ask whether there exists a version for windows XP. I am afraid I am still using them.
Sincerely.
Posts: 12,097
Threads: 142
Joined: Dec 2002
Try this. But possibly will not work with mobile device folder. I cannot test.
Macro Macro2744
out
;str sourceFolder="C:\Windows"
str sourceFolder="Phone Model\Mass memory\Logs"
str destFolder="Q:\Test\Sub"
;str files="*.ini"
str files="*.csv"
;get Shell32.Folder of the source folder (Phone Model\Mass memory\Logs)
Shell32.Shell x._create
Shell32.Folder fMC=x.NameSpace(Shell32.ssfDRIVES) ;;My Computer
Shell32.FolderItem fi=fMC.ParseName(sourceFolder)
if(!fi) end "failed"
;out fi.Name
Shell32.Folder folder1=fi.GetFolder
;get Shell32.Folder of the destination folder
Shell32.Folder folder2=x.NameSpace(destFolder)
if(!folder2) end "failed"
;get source folder items
ARRAY(Shell32.FolderItem) a
foreach fi folder1.Items
,str name=fi.Name
,;out name
,if(files.len and !matchw(name files 1)) continue
,out name
,a[]=fi
;copy
if(!a.len) out "0 matching files"; ret
int i
for i 0 a.len
,folder2.CopyHere(a[i] 4|16) ;;4 no progress, 16 overwrite silently
,
Posts: 1,058
Threads: 367
Joined: Oct 2007
Gintaras, thank you! I will try it and let you know accordingly.
Posts: 1,058
Threads: 367
Joined: Oct 2007
Actually it fails after statement Quote:Shell32.FolderItem fi=fMC.ParseName(sourceFolder)
Posts: 12,097
Threads: 142
Joined: Dec 2002
Macro Macro2745
out
Shell32.Shell x._create
Shell32.Folder fMC=x.NameSpace(Shell32.ssfDRIVES) ;;My Computer
Shell32.FolderItem fi
foreach fi fMC.Items
,str name=fi.Name
,out name
Does it show "Phone Model" or similar?
Posts: 1,058
Threads: 367
Joined: Oct 2007
Yes, it shows 13 items in My Computer, including the phone model.
Posts: 12,097
Threads: 142
Joined: Dec 2002
Then you can get Folder interface of the phone model folder (fMC=fi.GetFolder), enumerate its children to find Mass memory folder and so on, until Logs.
When you have Logs Folder interface, call its method CopyHere. I don't know if it will succeed on Windows XP, cannot test.
Posts: 1,058
Threads: 367
Joined: Oct 2007
Thank you very much for your invaluable help. I had already started doing so. I will report the result and also the code to be generated. Best regards.
Posts: 1,058
Threads: 367
Joined: Oct 2007
Dear Gintaras,
I am happy that it succeeded, thanks to your excellent instructions. I attach the final code. Best regards.
Macro Macro2745
;Copying files from Symbian-S60 phone to disk GC
;www.quickmacros.com/forum/viewtopic.php?p=30109
;---> Comment 25-10-2015 18:53:09 : Lemma
;Then you can get Folder interface of the phone model folder (fMC=fi.GetFolder),
;enumerate its children to find Mass memory folder and so on, until Logs.
;When you have Logs Folder interface, call its method CopyHere. I don't know if it
;will succeed on Windows XP, cannot test. Gintaras.
out
Shell32.Shell x._create
Shell32.Folder fMC=x.NameSpace(Shell32.ssfDRIVES) ;;My Computer
Shell32.FolderItem fi
foreach fi fMC.Items
,str name=fi.Name
;,out name
,if StrCompare(name "My mobile model")=0
,,fMC=fi.GetFolder
,,break
foreach fi fMC.Items
,name=fi.Name
;,out name
,if StrCompare(name "Mass memory")=0
,,fMC=fi.GetFolder
,,break
foreach fi fMC.Items
,name=fi.Name
;,out name
,if StrCompare(name "Logs")=0
,,fMC=fi.GetFolder
,,break
;get source folder items
str files="*.csv"
ARRAY(Shell32.FolderItem) a
foreach fi fMC.Items
,name=fi.Name
,out name
,if(files.len and !matchw(name files 1)) continue
,out name
,a[]=fi
,
if(!a.len) out "0 matching files"; ret
;copy
str destFolder="C:\tmp"
Shell32.Folder folder2=x.NameSpace(destFolder)
if(!folder2) end "failed"
int i
for i 0 a.len
,folder2.CopyHere(a[i] 4|16) ;;4 no progress, 16 overwrite silently
Posts: 858
Threads: 196
Joined: Apr 2005
Is possible to combine functions CopyFilesFromVirtualFolder and BackupFiles?
Posts: 12,097
Threads: 142
Joined: Dec 2002
Possible, but not easy to implement all options, for example 'replace if source is newer'. Because files in virtual folder don't have path, instead need to use either ITEMIDLIST or IShellItem objects. And I don't have such virtual folders for testing.
|