SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 06/01/2012, 08:42 PM   #1
Terminator3
Big Clucker
 
Terminator3's Avatar
 
Join Date: Oct 2009
Posts: 137
Reputation: 21
Default Directory 2.0

This is a continuation and refinement rather my previous plugin with that name klik

Functions:

DIR: DirOpen(const dirname[])
opens the directory to read it (You can open up to 32 folders at the same time)
  • const dirname[] - name of a directory

Return false if directory doesn't exist


DirClose(DIR:dir)
closes open directory
  • DIR:dir - id of a directory returned by DirOpen

Return true if directory has closed without any problems


DirRead(DIR:dir, name[])
Gets the name and type of element from directory
  • DIR:dir - id of a directory returned by DirOpen
  • name[] - return name of element

Return the element type*


DirRewind(DIR:dir)
Function moves a place to start reading a folder
  • DIR:dir - id of a directory returned by DirOpen

Returns true if the id of a directory is correct


DirCreate(const name[], mode = 420)
Creates a directory
  • const name[] - name of a directory
  • mode - chmod, unused on Windows

Returns true if the directory is correctly created


Rename(const oldname[], const newname[])
Renames a file / directory or move it to another location
  • const oldname[] - old name of a file/directory or the old localization
  • const newname[] - new name of a file/directory or the new localization

Returns true if the operation is performed correctly


CheckPath(const patch[])
Checks the type of element
  • const patch[] - name of file/directory

Returns the element type (directory, file)*


DirRemove(const name[], bool:empty = false)
Removes a directory and all subfolders and files inside
  • const name[] - name of a directory
  • bool:empty = false - if you know the directory is empty set this to true

Return 'true' if directory has been successfully removed


Chmod(const patch[], mode)
Sets the chmod of a directory/file
  • const patch[] - name of element
  • mode - mode, e.g. S_IREAD | S_IWRITE | S_IRGRP | S_IROTH or IntToOctal(644)

Windows
Linux
(names are the same in my dir.inc)

*Types of element (definitions):
type_unknown - not found or unknown type
type_dir - directory
type_file - file
type_other - other type

if you want to use chmod on Windows and you script gonna work only on Windows paste
Code:
#define WIN32
//or
#define WIN
above
Code:
#include <dir>

DOWNLOAD:
Windows .dll
Linus .so (on Ubuntu 11.04)
Includ .inc

and

soucre code

Mirror:
Direct download (all files)

Example:
Code:
new str[100],
	type,
	DIR:xxx = DirOpen("."); // scriptfiles

if(!xxx)
	return print("directory not found");

type = DirRead(xxx, str);
while(str[0])
{
	printf("\'%s\' type: %d", str, type);
	type = DirRead(xxx, str);
}
DirClose(xxx);
__________________
sorry for my bad English

Last edited by Terminator3; 13/02/2012 at 05:03 PM.
Terminator3 is offline   Reply With Quote
Old 06/01/2012, 08:49 PM   #2
Meta
Gangsta
 
Meta's Avatar
 
Join Date: Feb 2010
Posts: 650
Reputation: 47
Default AW: Directory 2.0

Looks good
I'll try it!

EDIT:
Quote:
Originally Posted by Terminator3 View Post
DirCreate(const name[])
Rename(const oldname[], const newname[])
From older plugin, that's a functions from C, mkdir and rename, (return == 0)
Little mistake?
Meta is offline   Reply With Quote
Old 06/01/2012, 08:51 PM   #3
Jovanny
Banned
 
Join Date: Oct 2010
Location: Siиαloα
Posts: 1,463
Reputation: 0
Default Respuesta: Directory 2.0

Good job, its useful
Jovanny is offline   Reply With Quote
Old 06/01/2012, 08:51 PM   #4
[Nikk]
High-roller
 
[Nikk]'s Avatar
 
Join Date: Jun 2011
Location: Argentina.
Posts: 1,491
Reputation: 63
Default Respuesta: Directory 2.0

Looks very nice men, i will try this
__________________


[Nikk] is offline   Reply With Quote
Old 06/01/2012, 08:54 PM   #5
steki.
High-roller
 
steki.'s Avatar
 
Join Date: Nov 2010
Location: São Paulo, Brasil
Posts: 2,572
Reputation: 315
Default Re: Directory 2.0

Looks nice.
__________________
Rio
steki. is offline   Reply With Quote
Old 06/01/2012, 09:33 PM   #6
TheArcher
High-roller
 
TheArcher's Avatar
 
Join Date: Dec 2009
Location: Home
Posts: 2,423
Reputation: 251
Default Re: Directory 2.0

It could be useful if this detect how many files are in the directory, what format is that file in the directory and such.
__________________
TheArcher is offline   Reply With Quote
Old 07/01/2012, 03:29 AM   #7
Babul
High-roller
 
Babul's Avatar
 
Join Date: Sep 2009
Location: in a cement block
Posts: 1,893
Reputation: 251
Default Re: Directory 2.0

hohoho! this plugin surely takes away some pain of scripting with .catalogue files, its really handy, thank you!
one question: do you intent to let the DirRead() output its content sorted? i could need that for easier browsing through numbered files :O)
Babul is offline   Reply With Quote
Old 07/01/2012, 03:43 AM   #8
[O.z]Caroline
High-roller
 
[O.z]Caroline's Avatar
 
Join Date: Sep 2011
Location: Brazil
Posts: 1,455
Reputation: 97
Default Re: Directory 2.0

Very nice!
__________________
[O.z]Caroline is offline   Reply With Quote
Old 07/01/2012, 08:42 AM   #9
Terminator3
Big Clucker
 
Terminator3's Avatar
 
Join Date: Oct 2009
Posts: 137
Reputation: 21
Default Re: Directory 2.0

Quote:
Originally Posted by Babul View Post
hohoho! this plugin surely takes away some pain of scripting with .catalogue files, its really handy, thank you!
one question: do you intent to let the DirRead() output its content sorted? i could need that for easier browsing through numbered files :O)
DirRead (readdir from dirent.h) has already sorts files by name, just is some small difference on linux

EDIT:
small update
__________________
sorry for my bad English

Last edited by Terminator3; 07/01/2012 at 09:33 AM.
Terminator3 is offline   Reply With Quote
Old 07/01/2012, 10:55 AM   #10
GangsTa_
High-roller
 
GangsTa_'s Avatar
 
Join Date: May 2010
Location: Republic of Moldova
Posts: 1,128
Reputation: 51
Default Re: Directory 2.0

That's nice, might be useful for some things.
__________________
i5-5200U @ 2.6 GHz
GTX 950M 2GB GDDR3 128-bit
8,00GB DDR3 RAM
128GB SSD, 1TB 5400RPM HDD
Windows 10 Pro x64
GangsTa_ is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
.AMX in Root directory. Hoborific Scripting Help 9 23/11/2011 04:00 PM
read out directory? hipy Help Archive 3 02/03/2011 07:56 PM
Creating Directory Gforcez1337 Help Archive 2 26/12/2010 04:17 PM
Reading directory mick88 Help Archive 2 19/12/2010 03:10 PM
[Plugin] Directory Terminator3 Plugin Development 11 05/12/2010 10:15 AM


All times are GMT. The time now is 01:24 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.