erazer
Junior Member
Posts: 61
|
Post by erazer on Feb 15, 2009 15:56:01 GMT -5
I need to combine RelativePaths and paths in FilesList.Add(MyFolder+'\*.*'); I do not know which files AND FOLDERS can contain MyFolder, so I can't make RootDir :='MyFolder' FilesList.Add('*.*') Also I need to zip MyFolder at one folder and restore in another, BUT relative to other folder. Example: c:\123\456\myfolder\dfds\1.txt to c:\123\789\myfolder\dfds\1.txt In this case I need to make RootDir :='c:\123\456\myfolder\' and FilesList.Add('dfds\*.*') but it does not work
|
|
erazer
Junior Member
Posts: 61
|
Post by erazer on Feb 15, 2009 16:51:14 GMT -5
May be a bit complicated.. In other words, i need to zip 3 folders (from different places) with all files and subfolders inside to one zip file without temporary files,and without fullpath before but with fullpath after is it possible? I.e. Myfolder\123\aaa\zzzz\*.*, Myfolder\123\aaa\ffff\*.* I want to zip as aaa\zzzz, aaa\ffff. Can I?
|
|
|
Post by Kevin on Feb 16, 2009 8:53:55 GMT -5
I'm sorry, I think I am still confused about what you are trying to do. 1) But, I can see one thing you are doing that you should not, and that is to use relative paths in FilesList. Even when you set RootDir you should still use full paths in FilesList. So I'm not sure if that is what is causing your problem or not. 2) Also, it may help to know that you can use RootDir to your advantage when unzipping too. If you set RootDir when unzipping, whatever is in RootDir will be stripped from the paths that are stored in the archive as the files are being unzipped. So if you are unzipping and have an archive with \dir1\dir2\sub1\file1.txt \dir1\dir2\sub2\file2.txt \dir1\dir2\sub3\file3.txt and you set RootDir := '\dir1\dir2\'; DestDir := 'c:\mydir\'; RecreateDirs := True; and unzip you will end up with the following files unzipped c:\mydir\sub1\file1.txt c:\mydir\sub2\file2.txt c:\mydir\sub3\file3.txt 3) One other thing you can possibly use is the OnStartZip and OnStartUnzip events. These events get called just before each file is zipped/unzipped. They allow you to modify things like the path. Look for them in the help file and that will explain more completely. I'm not sure if any of this helps or not. Maybe if you try one more time to explain what you are after I will understand. Kevin
|
|
erazer
Junior Member
Posts: 61
|
Post by erazer on Feb 16, 2009 15:49:13 GMT -5
Well I feel me stupid as never Actually I need to backup and restore 3 folders: C:\Users\User\AppData\Local\Microsoft\Windows Mail C:\Users\User\Favorites C:\Users\User\Contacts Of course C:\Users\User may be any C:\Users\BigBoss for example, so as I understand I have to backup Windows Mail\*.*,Favorites\*.*,Contacts\*.* Now I backup Favorites to one zip file, Contacts to another, and Windows Mail+Contacts.zip+Favorites.zip. So can I zip three folders to one zip file as Windows Mail+Contacts+Favorites with all subfolders and files?
|
|
|
Post by Kevin on Feb 16, 2009 17:12:14 GMT -5
OK, you want to backup the following:
C:\Users\User\AppData\Local\Microsoft\Windows Mail\*.* C:\Users\User\Favorites\*.* C:\Users\User\Contacts\*.*
And do you want this for all users and you want relative paths stored from C:\Users?
You might try using wildcards like this:
RootDir := 'C:\Users'; RelativePaths := True; Recurse := True; // if you want subdirs FilesList.Add('C:\Users\*\Local\Microsoft\Windows Mail\*.*'); FilesList.Add('C:\Users\*\Favorites\*.*'); FilesList.Add('C:\Users\*\Contacts\*.*'); VCLZip.Zip;
Notice the ...\*\... in the paths being added to FilesList. This will get all directories (users) under the Users directory but will only get those specific directories under them.
And since you are using relative paths, the paths stored in the archive would be...
User1\AppData\Local\Microsoft\Windows Mail\ User1\Favorites\ User1\Contacts\ User2\AppData\Local\Microsoft\Windows Mail\ User2\Favorites\ User2\Contacts\
Does that help? Is that what you are looking for?
Kevin
|
|
erazer
Junior Member
Posts: 61
|
Post by erazer on Feb 16, 2009 18:05:34 GMT -5
Of course seems your variant is working, but we understand that c:\users\ is relative... That's why we have each time to get it through SHGetSpecialFolderLocation(0, CSIDL_FAVORITES, List); and '%USERPROFILE%\Contacts' so every time i do don know were exactly this folders are, and can't 'hardcode' "C:\Users\*\Contacts\" Every folder can have its own independent location when I zip it and another than unzip.
|
|
|
Post by Kevin on Feb 16, 2009 18:47:31 GMT -5
Yes, but when you use the call to SHGetSpecialFolderLocation, you do know the location. So whatever the result of that location is, that is what you should use for RootDir. And when unzipping, when you get the result from SHGetSpecialFolderLocation, that is what you should use for DestDir.
You would need to parse up to the first directory in the value returned by SHGetSpecialFolderLocation and use that for RootDir.
Maybe something like the following which you should only have to do once since the RootDir should be the same for all users:
SHGetSpecialFolderLocation(Application.Handle,CSIDL_FAVORITES,pidl) SHGetPathFromIDList(pidl,path); RootDir := { Parse left part of path up to 2nd '\' }
Kevin
|
|
erazer
Junior Member
Posts: 61
|
Post by erazer on Feb 17, 2009 3:15:20 GMT -5
Hm.... I read it 5 times but did not understand what do you mean. Sure it does not matter HOW I get path to favorites,contacts,windows mail, let's imagine I GOT them and all of them is DIFFERENT, what have I to do further? How should I zip them so I could further restore anyway, to ANY folder I need ? I found 1 way backup 2 folders (*.* files from them) separately and 2+1 at last. But could I backup them as folders with all files and subfolders inside to 1 zip file without intermediate zip files?
|
|
|
Post by Kevin on Feb 17, 2009 7:31:03 GMT -5
It's quite possible that I still am not understanding what you want. If they all have different root folders then you will have to store full paths. If you do that then its just a matter of: VCLZip.Recurse := True; VCLZip.StorePaths := True; FilesList.Add(FavoritesDir+'\*.*'); FilelsList.Add(ContactsDir+'\*.*'); FilesList.Add(MailDir+'\*.*'); VCLZip.Zip; Don't set RootDir at all. If they can all have different root directories then I can't think of how relative directories can be used. Kevin
|
|
|
|
Post by Kevin on Feb 17, 2009 17:28:28 GMT -5
I've re-read all of this thread and I think I understand what you are after. I guess you probably are best off zipping to separate zip files. You can use relative paths in each separate zip file and that makes it easy to unzip to wherever you want.
Trying to use separate rootdir's for each set of files in one archive would get quite messy and complicated given your scenario.
The ONLY way I can think of doing this is, using the OnStartZip and OnStartUnZip events as I was mentioning before. If you zip with full paths, you can use the OnStartZip event.
You can look at the ZipHeader.Pathname and if it is possible to tell which type it is by something in the path (Favorites, Contacts, etc) then you can replace the left part of the path with something like 'Favorites\'.
If there is no way to look at the path of the file about to be zipped then this won't work. But I would think you would be able to compare the path to the 3 paths that you came up with for each type to determine which it is.
Kevin
|
|
erazer
Junior Member
Posts: 61
|
Post by erazer on Feb 18, 2009 3:31:01 GMT -5
A bit entangled. Could you provide code example ?
|
|
|
Post by Kevin on Feb 18, 2009 8:53:55 GMT -5
Here is a stab at it. The following has not been tested so may require a bit of tweaking and testing...
First, get the 3 paths however you do it, for example...
SHGetSpecialFolderLocation(Application.Handle,CSIDL_FAVORITES,pidl) SHGetPathFromIDList(pidl,FavoritesPath); ... (get other paths)
Apply ExtractFilePath on each of these so that the 'C:' is removed.
so you have the following variables set with the appropriate paths
FavoritesPath ContactsPath MailPath
VCLZip.StorePaths := True; VCLZip.Recurse := True; VCLZip.Zip;
You should have an OnStartZip event something like the following which is called for each file just before it is zipped...
==================== procedure MyForm.OnStartZip( Sender: TObject; FName: String; var ZipHeader: TZipHeaderInfo; var Skip: Boolean ); begin
// Which type? if (Pos(FavoritesPath,ZipHeader.Pathname) > 0) then begin Delete(ZipHeader.Pathname,0,Length(FavoritesPath); ZipHeader.Pathname := 'Favorites\' + ZipHeader.Pathname; end else if (Pos(ContactsPath,ZipHeader.Pathname) > 0) then begin // same as above but with ContactsPath end else if (Pos(MailPath,ZipHeader.Pathname) > 0) then begin // same as above but with MailPath end
end; ================================
So for instance, say the FavoritesPath is "\somedir\MyFavorites". if OnStartZip was called just before a Favorite was about to be zipped, the ZipHeader.Pathname coming in might look like "\users\Joe\MyFavorites\Links". When the above code is run it should end up "Favorites\Links"
When Unzipping, set values in RelativePathList to strip the key that you added to each...
RelativePathList.Add('Favorites\'); RelativePathList.Add('Contacts'\'); RelativePathList.Add('Mail\');
Like I say, it may just be easier for you to continue to create 3 separate zip files. That is up to you.
Kevin
|
|
erazer
Junior Member
Posts: 61
|
Post by erazer on Feb 18, 2009 15:59:28 GMT -5
I can't understand some moments "Apply ExtractFilePath on each of these so that the 'C:' is removed." What's for ? "so you have the following variables set with the appropriate paths FavoritesPath ContactsPath MailPath" Do you mean FavoritesPath=\Users\User\Favorites ContactsPath=\Users\User\Contacts MailPath=\Users\User\AppData\Local\Microsoft\Windows Mail or something else ? "So for instance, say the FavoritesPath is "\somedir\MyFavorites". if OnStartZip was called just before a Favorite was about to be zipped, the ZipHeader.Pathname coming in might look like "\users\Joe\MyFavorites\Links". When the above code is run it should end up "Favorites\Links"" I had reread it in about 10 times but still can't understand you. I cant understand how we turn "\somedir\MyFavorites" into "\users\Joe\MyFavorites\Links" ?
|
|
erazer
Junior Member
Posts: 61
|
Post by erazer on Feb 18, 2009 16:03:08 GMT -5
What path contain FavoritesPath here if (Pos(FavoritesPath,ZipHeader.Pathname) > 0) then ? "C:\Users\User\Favorites" trimmed to "\Users\User\Favorites" ?
|
|