00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include <f32file.h>
00040 #include "CommonFramework.h"
00041
00042 LOCAL_D RFs fsSession;
00043
00044
00045 void DoDirectoryAttribsL();
00046 void PrintDirectoryListsL();
00047 void DeleteAllL();
00048
00049
00050 void FormatEntry(TDes& aBuffer, const TEntry& aEntry);
00051 void FormatAtt(TDes& aBuffer, const TUint aValue);
00052 void MakeSmallFileL(const TDesC& aFileName);
00053
00054 void WaitForKey()
00055 {
00056 _LIT(KMessage,"Press any key to continue\n");
00057 console->Printf(KMessage);
00058 console->Getch();
00059 }
00060
00061 LOCAL_C void doExampleL()
00062 {
00063
00064 User::LeaveIfError(fsSession.Connect());
00065
00066
00067
00068
00069
00070
00071
00072 fsSession.CreatePrivatePath(RFs::GetSystemDrive());
00073
00074
00075
00076 fsSession.SetSessionToPrivate(RFs::GetSystemDrive());
00077
00078
00079 DoDirectoryAttribsL();
00080 WaitForKey();
00081 PrintDirectoryListsL();
00082 WaitForKey();
00083 DeleteAllL();
00084
00085
00086 fsSession.Close();
00087 }
00088
00089 void DoDirectoryAttribsL()
00090 {
00091
00092 _LIT(KAttsMsg,"\nAttributes and entry details\n");
00093 _LIT(KDateString,"%D%M%Y%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%:3%+B");
00094 _LIT(KDateMsg,"Using Entry():\nModification time of %S is %S\n");
00095 _LIT(KSizeMsg,"Size = %d bytes\n");
00096 _LIT(KBuffer,"%S");
00097 _LIT(KEntryMsg,"Using Modified():\nModification time of %S is %S\n");
00098 _LIT(KAttMsg,"Using Att():\n%S");
00099
00100
00101 _LIT(KSubDirName,"f32examp\\");
00102 _LIT(KFileName,"tmpfile.txt");
00103
00104
00105
00106
00107
00108 console->Printf(KAttsMsg);
00109
00110
00111
00112 TFileName thePath;
00113 fsSession.PrivatePath(thePath);
00114 thePath.Append(KSubDirName);
00115
00116
00117 TInt err=fsSession.MkDir(thePath);
00118 if (err!=KErrAlreadyExists)
00119 User::LeaveIfError(err);
00120
00121
00122 thePath.Append(KFileName);
00123 MakeSmallFileL(thePath);
00124
00125
00126 TEntry entry;
00127 User::LeaveIfError(fsSession.Entry(thePath,entry));
00128 TBuf<30> dateString;
00129 entry.iModified.FormatL(dateString,KDateString);
00130
00131
00132 console->Printf(KDateMsg,&entry.iName,&dateString);
00133
00134
00135 console->Printf(KSizeMsg,entry.iSize);
00136 TBuf<80> buffer;
00137 FormatEntry(buffer,entry);
00138 console->Printf(KBuffer,&buffer);
00139 buffer.Zero();
00140
00141
00142 TTime time;
00143 User::LeaveIfError(fsSession.Modified(thePath,time));
00144 time.FormatL(dateString,KDateString);
00145
00146
00147 console->Printf(KEntryMsg,&entry.iName,&dateString);
00148 TUint value;
00149 User::LeaveIfError(fsSession.Att(thePath,value));
00150 FormatAtt(buffer,value);
00151 console->Printf(KAttMsg,&buffer);
00152 buffer.Zero();
00153
00154
00155 User::LeaveIfError(fsSession.SetEntry(thePath,time,
00156 NULL,KEntryAttArchive));
00157 }
00158
00159 void PrintDirectoryListsL()
00160 {
00161
00162 _LIT(KListMsg,"\nDirectory listings\n");
00163 _LIT(KListMsg2,"\nDirectories and files:\n");
00164 _LIT(KDirList,"%S\n");
00165 _LIT(KDirs,"\nDirectories:\n");
00166 _LIT(KFilesSizes,"\nFiles and sizes:\n");
00167 _LIT(KBytes," %d bytes\n");
00168 _LIT(KNewLine,"\n");
00169
00170
00171 _LIT(KDir1,"f32examp\\tmpdir1\\");
00172 _LIT(KDir2,"f32examp\\tmpdir2\\");
00173 _LIT(KFile2,"f32examp\\tmpfile2.txt");
00174 _LIT(KDirName,"f32examp\\*");
00175
00176
00177
00178
00179
00180
00181 console->Printf(KListMsg);
00182
00183 TFileName thePrivatePath;
00184 fsSession.PrivatePath(thePrivatePath);
00185
00186 TFileName thePath;
00187 TInt err;
00188
00189
00190 thePath = thePrivatePath;
00191 thePath.Append(KDir1);
00192 err=fsSession.MkDir(thePath);
00193 if (err!=KErrAlreadyExists)
00194 User::LeaveIfError(err);
00195
00196
00197 thePath = thePrivatePath;
00198 thePath.Append(KDir2);
00199 err=fsSession.MkDir(thePath);
00200 if (err!=KErrAlreadyExists)
00201 User::LeaveIfError(err);
00202
00203
00204 thePath = thePrivatePath;
00205 thePath.Append(KFile2);
00206 MakeSmallFileL(thePath);
00207
00208
00209
00210
00211 thePath = thePrivatePath;
00212 thePath.Append(KDirName);
00213 CDir* dirList;
00214
00215
00216
00217 User::LeaveIfError(fsSession.GetDir(thePath,KEntryAttMaskSupported,ESortByName,dirList));
00218 console->Printf(KListMsg2);
00219 TInt i;
00220 for (i=0;i<dirList->Count();i++)
00221 console->Printf(KDirList,&(*dirList)[i].iName);
00222 delete dirList;
00223
00224
00225 CDir* fileList;
00226 User::LeaveIfError(fsSession.GetDir(thePath,KEntryAttNormal,ESortByName,fileList,dirList));
00227 console->Printf(KDirs);
00228 for (i=0;i<dirList->Count();i++)
00229 console->Printf(KDirList,&(*dirList)[i].iName);
00230 console->Printf(KFilesSizes);
00231 for (i=0;i<fileList->Count();i++)
00232 {
00233 console->Printf(KDirList,&(*fileList)[i].iName);
00234 console->Printf(KBytes,(*fileList)[i].iSize);
00235 }
00236 console->Printf(KNewLine);
00237 delete dirList;
00238 delete fileList;
00239
00240 }
00241
00242 void DeleteAllL()
00243
00244 {
00245
00246 _LIT(KDeleteMsg,"\nDeleteAll()\n");
00247 _LIT(KFile2,"f32examp\\tmpfile2.txt");
00248 _LIT(KDir1,"f32examp\\tmpdir1\\");
00249 _LIT(KDir2,"f32examp\\tmpdir2\\");
00250 _LIT(KFile1,"f32examp\\tmpfile.txt");
00251 _LIT(KTopDir,"f32examp\\");
00252 console->Printf(KDeleteMsg);
00253
00254 TFileName thePrivatePath;
00255 fsSession.PrivatePath(thePrivatePath);
00256
00257 TFileName thePath;
00258
00259 thePath = thePrivatePath;
00260 thePath.Append(KFile2);
00261 User::LeaveIfError(fsSession.Delete(thePath));
00262
00263 thePath = thePrivatePath;
00264 thePath.Append(KDir1);
00265 User::LeaveIfError(fsSession.RmDir(thePath));
00266
00267 thePath = thePrivatePath;
00268 thePath.Append(KDir2);
00269 User::LeaveIfError(fsSession.RmDir(thePath));
00270
00271 thePath = thePrivatePath;
00272 thePath.Append(KFile1);
00273 User::LeaveIfError(fsSession.Delete(thePath));
00274
00275 thePath = thePrivatePath;
00276 thePath.Append(KTopDir);
00277 User::LeaveIfError(fsSession.RmDir(thePath));
00278 }
00279
00280 void MakeSmallFileL(const TDesC& aFileName)
00281 {
00282 _LIT8(KFileData,"Some data");
00283 RFile file;
00284 User::LeaveIfError(file.Replace(fsSession,aFileName,EFileWrite));
00285 User::LeaveIfError(file.Write(KFileData));
00286 User::LeaveIfError(file.Flush());
00287 file.Close();
00288 }
00289
00290 void FormatEntry(TDes& aBuffer, const TEntry& aEntry)
00291 {
00292 _LIT(KEntryDetails,"Entry details: ");
00293 _LIT(KReadOnly," Read-only");
00294 _LIT(KHidden," Hidden");
00295 _LIT(KSystem," System");
00296 _LIT(KDirectory," Directory");
00297 _LIT(KArchive," Archive");
00298 _LIT(KNewLIne,"\n");
00299 aBuffer.Append(KEntryDetails);
00300 if(aEntry.IsReadOnly())
00301 aBuffer.Append(KReadOnly);
00302 if(aEntry.IsHidden())
00303 aBuffer.Append(KHidden);
00304 if(aEntry.IsSystem())
00305 aBuffer.Append(KSystem);
00306 if(aEntry.IsDir())
00307 aBuffer.Append(KDirectory);
00308 if(aEntry.IsArchive())
00309 aBuffer.Append(KArchive);
00310 aBuffer.Append(KNewLIne);
00311 }
00312
00313 void FormatAtt(TDes& aBuffer, const TUint aValue)
00314 {
00315 _LIT(KAttsMsg,"Attributes set are:");
00316 _LIT(KNormal," Normal");
00317 _LIT(KReadOnly," Read-only");
00318 _LIT(KHidden," Hidden");
00319 _LIT(KSystem," System");
00320 _LIT(KVolume," Volume");
00321 _LIT(KDir," Directory");
00322 _LIT(KArchive," Archive");
00323 _LIT(KNewLine,"\n");
00324 aBuffer.Append(KAttsMsg);
00325 if (aValue & KEntryAttNormal)
00326 {
00327 aBuffer.Append(KNormal);
00328 return;
00329 }
00330 if (aValue & KEntryAttReadOnly)
00331 aBuffer.Append(KReadOnly);
00332 if (aValue & KEntryAttHidden)
00333 aBuffer.Append(KHidden);
00334 if (aValue & KEntryAttSystem)
00335 aBuffer.Append(KSystem);
00336 if (aValue & KEntryAttVolume)
00337 aBuffer.Append(KVolume);
00338 if (aValue & KEntryAttDir)
00339 aBuffer.Append(KDir);
00340 if (aValue & KEntryAttArchive)
00341 aBuffer.Append(KArchive);
00342 aBuffer.Append(KNewLine);
00343 }
00344