

% add the PATH to retrieve cls and sty beamer styles files
\makeatletter
\providecommand*{\input@path}{}
\edef\input@path{{../../support/beamer/}\input@path}% prepend
\makeatother

% \documentclass{pharoslides}
% \documentclass[aspectratio=169]{pharoslides} % format 16/9
\documentclass[withvideo]{pharoslides} % format 16/9 + incrustation video

\graphicspath{{./figures/}{../}{../../support/beamer/imgs/}}

%Information to be included in the title page:
\title{Files in Pharo}
\subtitle{}
\author{Damien Cassou, Stéphane Ducasse and Luc Fabresse}
\institute{http://stephane.ducasse.free.fr}
\date{}
\slidesid{W5S07}

\begin{document}

\frame[plain]{\titlepage}



\begin{frame}[fragile]

\frametitle{What You Will Learn}

\begin{itemize}
\item Navigating between directories
\item Creating and removing directories
\item Listing files
\item Reading from and writing to files
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Getting Started}

Some standard directories

\begin{listing}{}
FileLocator home.   "User's home directory (~)"
FileLocator root.   "File system's root (/)"
FileLocator C.      "Windows C:\"
\end{listing}

Accessing the children of a directory

\begin{listing}{}
| home |
home := FileLocator home.

home pathString
> '/home/cassou/'

home children
> an Array({home}/.bashrc {home}/Music ...)
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Navigating Up and Down}

Use message \code{/} to build a path

\begin{listing}{}
(home / 'Music') directories
> an Array({home}/Music/Anouar_Brahem ...)
\end{listing}

Use \code{parent} to go up

\begin{listing}{}
(home / 'Music') parent pathString
> '/home/cassou/'
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Creating and Removing Directories}

\begin{listing}{}
| music |
music := FileLocator home / 'Music'.
(music / 'Pink_Floyd') isDirectory.
> false

(music / 'Pink_Floyd') ensureCreateDirectory.
(music / 'Pink_Floyd') isDirectory.
> true

(music / 'Pink_Floyd') delete.
(music / 'Pink_Floyd') isDirectory
> false
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Finding Children}

\begin{listing}{}
(pinkFloyd / 'Meddle') allChildrenMatching: '*.ogg'.
\end{listing}

is equivalent to

\begin{listing}{}
(pinkFloyd / 'Meddle') allChildren
   select: [ :each | each basename endsWith: 'ogg' ]
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Getting Information}

\begin{listing}{}
| pharo |
pharo := 'pharo5.image' asFileReference.

pharo isFile.
> true

pharo basename
> 'pharo5.image'

pharo extension
> 'image'

pharo size
> 23744868

pharo parent pathString
> '/home/cassou/Pharo/images/pharo5'
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Writing to a File}

\begin{listing}{}
| hello stream |
hello := 'hello.txt' asFileReference.
hello exists
> false

stream := hello writeStream.
stream nextPutAll: 'Hello World'.
stream close.
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Reading from a File}

\begin{listing}{}
| hello stream |
hello := 'hello.txt' asFileReference.
hello exists
> true

stream := hello readStream.
stream next.
> $H

stream upToEnd.
> 'ello World'

stream close
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Automatically Closing File Streams}

\begin{listing}{}
| hello |
hello := 'hello.txt' asFileReference.
\end{listing}

Writing

\begin{listing}{}
hello writeStreamDo: [ :stream |
   stream nextPutAll: 'Hello World'].
\end{listing}

Reading

\begin{listing}{}
hello readStreamDo: [ :stream | stream contents ]
> 'Hello World'
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{What You Should Know}

\begin{itemize}
\item File and directory references are objects
\item The simple API facilitates navigation and manipulation
\item Reading from and writing to files is done through streams
\end{itemize}
\end{frame}




% \setlength{\textwidth}{\originaltextwidth}
\setbeamertemplate{background canvas}{\insertBorderForHandout}

\begin{frame}[plain]

\begin{minipage}{\originaltextwidth}
\centering
\large


\vspace{2em}

A course by

\vspace{1em}

\hspace{-20px}\includegraphics[height=32px]{inriaLogo}\hspace{3em}\raisebox{7px}{and}\hspace{3em}\raisebox{-6px}{\includegraphics[height=30px]{logoutop}}

\vspace{2em}

in collaboration with

\vspace{1em}

\includegraphics[height=40px]{unisciellogo}\hskip 1.5em%
\raisebox{5px}{\includegraphics[height=30px]{unitlogo}}\hskip 2em%
\raisebox{8px}{\includegraphics[height=24px]{univLilleLogo}}\hskip 2em%
\raisebox{3px}{\includegraphics[height=29px]{logo-IMT}}\hskip 2em%
\raisebox{1px}{\includegraphics[height=32px]{minesDouaiLogo}}

\vspace{2.5em}

\includegraphics[width=50px]{by-nc-nd} \tiny \hskip 0.5em \raisebox{5px}{Inria 2016}

\medskip

\tiny
Except where otherwise noted, this work is licensed under CC BY-NC-ND 3.0 France

\url{https://creativecommons.org/licenses/by-nc-nd/3.0/fr/} 

\end{minipage}
\end{frame}

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
