Warning: strpos() [function.strpos]: Empty needle in /home/dealer/kasat/pkg/cahir/web/html/lib/plugins/translation2/action.php on line 53

Warning: Cannot modify header information - headers already sent by (output started at /home/dealer/kasat/pkg/cahir/web/html/lib/plugins/translation2/action.php:53) in /home/dealer/kasat/pkg/cahir/web/html/inc/actions.php on line 163
erlang:files [Krystian Bacławski Wiki]
 

Obsługa plików

file:format_error(Reason) -> Chars

Pliki i katalogi

Działania na plikach

file:copy(Source, Destination) ->
file:copy(Source, Destination, ByteCount) -> {ok, BytesCopied} | {error, Reason}
file:delete(Filename) -> ok | {error, Reason}
file:rename(Source, Destination) -> ok | {error, Reason}

Informacje o plikach

Wszystko

file:read_file_info(Filename) -> {ok, FileInfo} | {error, Reason}
file:write_file_info(Filename, FileInfo) -> ok | {error, Reason}

Przykład

> file:read_file_info("README.txt").
{ok,
  {file_info,
   564,                      % size
   regular,                  % type
   read_write,               % dostęp dla bieżącego użytkownika
   {{2010,5,31},{23,38,57}}, % mtime
   {{2010,4,21},{11,35,27}}, % ctime
   {{2010,6,1},{0,13,7}},    % atime
   33188,                    % perm = 100644 (regular file, rw-r--r--)
   1,                        % links
   2054,                     % major_dev
   0,                        % minor_dev
   941477036,                % inode
   1000,                     % uid
   1000}}                    % gid

Rozmiar

filelib:file_size(Filename) -> integer()

Typ

filelib:is_dir(Name) -> true | false
filelib:is_file(Name) -> true | false
filelib:is_regular(Name) -> true | false

Właściciel i grupa

file:change_owner(Filename, Uid) -> ok | {error, Reason}
file:change_owner(Filename, Uid, Gid) -> ok | {error, Reason}
file:change_group(Filename, Gid) -> ok | {error, Reason}

Czas

file:change_time(Filename, Mtime) -> ok | {error, Reason}
file:change_time(Filename, Mtime, Atime) -> ok | {error, Reason}
filelib:last_modified(Name) -> {{Year,Month,Day},{Hour,Min,Sec}} | 0

Działania na katalogach

file:get_cwd() -> {ok, Dir} | {error, Reason}
file:set_cwd(Dir) -> ok | {error,Reason}
file:del_dir(Dir) -> ok | {error, Reason}
file:make_dir(Dir) -> ok | {error, Reason}
file:list_dir(Dir) -> {ok, Filenames} | {error, Reason}
filelib:ensure_dir(Name) -> ok | {error, Reason}

Działania na łączach

file:read_link(Name) -> {ok, Filename} | {error, Reason}
file:read_link_info(Name) -> {ok, FileInfo} | {error, Reason}
file:make_link(Existing, New) -> ok | {error, Reason}
file:make_symlink(Name1, Name2) -> ok | {error, Reason}

Operowanie na ścieżkach

Ścieżka absolutna

filename:absname(Filename) -> string()
filename:absname(Filename, Dir) ->  string()
filename:absname_join(Dir, Filename) -> string()
filename:pathtype(Path) -> absolute | relative | volumerelative

Podział ścieżki na katalog i plik

filename:basename(Filename) -> string()
filename:basename(Filename, Ext) -> string()
filename:dirname(Filename) -> string()

Rozszerzenie i część bazowa

filename:extension(Filename) -> string()
filename:rootname(Filename) -> string()

Przykład

> filename:extension("README.txt").
".txt"
> filename:rootname("README.txt").
"README"

Podział i scalanie ścieżki

filename:join(Components) -> string()
filename:split(Filename) -> Components
filename:nativename(Path) -> string()

Przykład

> {ok, Cwd} = file:get_cwd().
{ok,"/media/Dane/workspace/llvm"}
 
> filename:join([Cwd,"README.txt"]).
"/media/Dane/workspace/llvm/README.txt"
 
> filename:split(Readme).
["/","media","Dane","workspace","llvm","README.txt"]

Dopasowanie nazw

filelib:fold_files(Dir, RegExp, Recursive, Fun, AccIn) -> AccOut
filelib:wildcard(Wildcard) -> list()
filelib:wildcard(Wildcard, Cwd) -> list()

Przykład

> filelib:wildcard("*.txt").
["CMakeLists.txt","ModuleInfo.txt","README.txt"]

Odnajdowanie źródeł erlangowych

filename:find_src(Beam) -> {SourceFile, Options} | {error,{ErrorReason,Module}}
filename:find_src(Beam, Rules) -> {SourceFile, Options} | {error,{ErrorReason,Module}}

Operacje wejścia/wyjścia

Podstawy

Otwieranie plików
file:open(Filename, Modes) -> {ok, IoDevice} | {error, Reason}
file:path_open(Path, Filename, Modes) -> {ok, IoDevice, FullName} | {error, Reason}
Uchwyt pliku
file:pid2name(Pid) -> string() | undefined
Zamykanie
file:close(IoDevice) -> ok | {error, Reason}

Przykład

> {ok, Io} = file:open("README.txt", read).
{ok,<0.54.0>}
 
> file:pid2name(Io).
{ok,"README.txt"}
 
> file:close(Io).
ok

Pozycja kursora

file:position(IoDevice, Location) -> {ok, NewPosition} | {error, Reason}

Synchronizacja zawartości

file:sync(IoDevice) -> ok | {error, Reason}

Zerowanie zawartości

file:truncate(IoDevice) -> ok | {error, Reason}

Odczyt zawartości

Cały plik na raz:

file:read_file(Filename) -> {ok, Binary} | {error, Reason}
file:read(IoDevice, Number) -> {ok, Data} | eof | {error, Reason}
file:pread(IoDevice, LocNums) ->  {ok, DataL} | eof | {error, Reason}
file:pread(IoDevice, Location, Number) -> {ok, Data} | eof | {error, Reason}

Przykład

> file:read(Io, 300).
{ok,"first line\nsecond line\n..."}
> file:read(Io, 300).
{ok,"thirtieth line\n..."}
> file:read(Io, 300).
eof
file:read_line(IoDevice) -> {ok, Data} | eof | {error, Reason}

Przykład

> file:read_line(Io).
{ok,"first line\n"}
26> file:read_line(Io).
{ok,"second line\n"}

Zapis zawartości

file:write(IoDevice, Bytes) -> ok | {error, Reason}
file:pwrite(IoDevice, LocBytes) -> ok | {error, {N, Reason}}
file:pwrite(IoDevice, Location, Bytes) -> ok | {error, Reason}
file:write_file(Filename, Bytes) -> ok | {error, Reason}
file:write_file(Filename, Bytes, Modes) -> ok | {error, Reason}

Interpretacja zawartości

Wczytuje uproszczone wyrażenia erlangowe zakończone kropką.

file:consult(Filename) -> {ok, Terms} | {error, Reason}
file:path_consult(Path, Filename) -> {ok, Terms, FullName} | {error, Reason}

Wczytuje wyrażenia erlangowe zakończone kropką i je oblicza. Nie zwraca wyniku.

file:eval(Filename) -> ok | {error, Reason}
file:eval(Filename, Bindings) -> ok | {error, Reason}
file:path_eval(Path, Filename) -> {ok, FullName} | {error, Reason}

Wczytuje wyrażenia erlangowe zakończone kropką i je oblicza. Zwraca wynik ostatniego wyrażenia.

file:script(Filename) -> {ok, Value} | {error, Reason}
file:script(Filename, Bindings) -> {ok, Value} | {error, Reason}
file:path_script(Path, Filename) -> {ok, Value, FullName} | {error, Reason}
file:path_script(Path, Filename, Bindings) -> {ok, Value, FullName} | {error, Reason}

Inne

Moduł io

io:columns([IoDevice]) -> {ok,int()} | {error, enotsup}
io:format(Format) -> ok
io:format([IoDevice,] Format, Data) -> ok
io:fread([IoDevice,] Prompt, Format) -> Result
io:fwrite(Format) -> ok
io:fwrite([IoDevice,] Format, Data) -> ok
io:get_chars([IoDevice,] Prompt, Count) -> Data | eof
io:get_line([IoDevice,] Prompt) -> Data | eof | {error,Reason}
io:getopts([IoDevice]) -> Opts
io:nl([IoDevice]) -> ok
io:put_chars([IoDevice,] IoData) -> ok
io:read(IoDevice, Prompt, StartLine) -> Result
io:read([IoDevice,] Prompt) -> Result
io:setopts([IoDevice,] Opts) -> ok | {error, Reason}
io:write([IoDevice,] Term) -> ok

Moduł io_lib

io_lib:nl() -> chars()
io_lib:write(Term) ->
io_lib:write(Term, Depth) -> chars()
io_lib:print(Term) ->
io_lib:print(Term, Column, LineLength, Depth) -> chars()
io_lib:fwrite(Format, Data) ->
io_lib:format(Format, Data) -> chars() | UnicodeList
io_lib:fread(Format, String) -> Result
io_lib:fread(Continuation, String, Format) -> Return
io_lib:write_atom(Atom) -> chars()
io_lib:write_string(String) -> chars()
io_lib:write_char(Integer) -> chars()
io_lib:indentation(String, StartIndent) -> int()
io_lib:char_list(Term) -> bool()
io_lib:deep_char_list(Term) -> bool()
io_lib:printable_list(Term) -> bool()

Źródła

Archiwa plików

Archiwa tar

Drukowanie błędów

erl_tar:format_error(Reason) -> string()

Tworzenie

erl_tar:create(Name, FileList) ->RetValue

Otwieranie i zamykanie

erl_tar:open(Name, OpenModeList) -> RetValue
erl_tar:close(TarDescriptor)

Dodawanie plików

erl_tar:add(TarDescriptor, Filename, Options) -> RetValue
erl_tar:add(TarDescriptor, FilenameOrBin, NameInArchive, Options) -> RetValue

Wypakowywanie plików

erl_tar:extract(Name) -> RetValue
erl_tar:extract(Name, OptionList)

Listowanie zawartości

erl_tar:table(Name) -> RetValue
erl_tar:table(Name, Options)

Archiwa zip

zip:zip(Name, FileList) -> RetValue
zip:zip(Name, FileList, Options) -> RetValue
zip:create(Name, FileList) -> RetValue
zip:create(Name, FileList, Options) -> RetValue
 
zip:unzip(Archive) -> RetValue
zip:unzip(Archive, Options) -> RetValue
zip:extract(Archive) -> RetValue
zip:extract(Archive, Options) -> RetValue
 
zip:list_dir(Archive) -> RetValue
zip:list_dir(Archive, Options)
zip:table(Archive) -> RetValue
zip:table(Archive, Options)
 
zip:zip_open(Archive) -> {ok, ZipHandle} | {error, Reason}
zip:zip_open(Archive, Options) -> {ok, ZipHandle} | {error, Reason}
zip:zip_list_dir(ZipHandle) -> Result | {error, Reason}
zip:zip_get(ZipHandle) -> {ok, [Result]} | {error, Reason}
zip:zip_get(FileName, ZipHandle) -> {ok, Result} | {error, Reason}
zip:zip_close(ZipHandle) -> ok | {error, einval}

Żródła

  • erl_tar - obsługa archiwów .tar, .tar.gz
  • zip - obsługa archiwów .zip
 
erlang/files.txt · Last modified: 2010/06/08 16:09 by Krystian Bacławski
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-No Derivative Works 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki