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