-
-
Notifications
You must be signed in to change notification settings - Fork 499
Add new functions: pathListDir, pathIsFile, pathIsDirectory
#3189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new functions: pathListDir, pathIsFile, pathIsDirectory
#3189
Conversation
Is this supposed to return a list of files in a directory?
Is this supposed to return a list of files in a directory?
Relative to a current resource, yes
Is the Unix code block functional with if (!(dir = opendir("c:\\src\\")))?
Also, don't you exclude the directory items in the < C++17 block?
And last, how can the scripter differentiate between file and directory?
Is the Unix code block functional with
if (!(dir = opendir("c:\\src\\")))? Also, don't you exclude the directory items in the< C++17block? And last, how can the scripter differentiate between file and directory?
- Changed path to the actual path. Should be functional now
- Now including all files in a directory without adding the directory name before it too
- via
isFileandisDirectoryfunctions (comment edited)
Wouldn't it make more sense to append a directory separator for directory items?
Checking each item whether it's a directory or file seems expensive?
Wouldn't it make more sense to append a directory separator for directory items?
It might cause some issues when messing with directories directly via that function (unless mta takes care of that already)
Checking each item whether it's a directory or file seems expensive?
No, it's not really expensive.
If MTA doesn't have problems with directories ending with \ | / then sure, I can add a separator for directory entries
I don't think fileListDir makes a lot of sense as a name.
Perhaps something like getDirectoryEntries or (or, I'd prefer to separate them, getDirectoryFiles and getDirectoryFolders, both with a bool recursive parameter as well.
Or, could even go with pathGetFolders, pathGetFiles [if we want to follow the file prefix convention thingy]
I don't think
fileListDirmakes a lot of sense as a name. Perhaps something likegetDirectoryEntriesor (or, I'd prefer to separate them,getDirectoryFilesandgetDirectoryFolders, both with abool recursiveparameter as well. Or, could even go withpathGetFolders,pathGetFiles[if we want to follow thefileprefix convention thingy]
its better to have one function that gets all entries that you can sort by using isFile/isDirectory functions.
There's the module FileSystem which already does the same and has some more features/functions btw.
Although could be added nativelly yes if the only purpose is to get files from a directory instead of using the module just for that.
There's the module FileSystem which already does the same and has some more features/functions btw.
Although could be added nativelly yes if the only purpose is to get files from a directory instead of using the module just for that.
Using module for that will decrease performance (since you have to load the module, load its functions and events not to mention modules are very limited and you cant use almost any MTA functions there at all without refactoring the whole mta server).
Also that would only make the command work in server scripts only.
Implementing it directly in MTA solves all these issues
There's the module FileSystem which already does the same and has some more features/functions btw.
Although could be added nativelly yes if the only purpose is to get files from a directory instead of using the module just for that.Using module for that will decrease performance (since you have to load the module, load its functions and events not to mention modules are very limited and you cant use almost any MTA functions there at all without refactoring the whole mta server). Also that would only make the command work in server scripts only.
Implementing it directly in MTA solves all these issues
Uhm I'm not sure if we really have these issues in the (FileSystem) module. But I do agree that having the functions client-side and being directly implemented into MTA is better.
There's the module FileSystem which already does the same and has some more features/functions btw.
Although could be added nativelly yes if the only purpose is to get files from a directory instead of using the module just for that.Using module for that will decrease performance (since you have to load the module, load its functions and events not to mention modules are very limited and you cant use almost any MTA functions there at all without refactoring the whole mta server). Also that would only make the command work in server scripts only.
Implementing it directly in MTA solves all these issues
I doubt that modules can affect performance in a context of filesystem functions. The main disadvantage that modules have - they don't exist on a client side. So the only way to add proposed in this PR functions is to make them a part of MTA.
But I personally would not say that these functions are really needed on a client side. Typically, server(and therefore client scripts) know which files exist on a client and how to reach them, which makes sense from the security perspective.
fileListDir (削除ここまで)pathListDir (追記ここまで)
pathListDir (削除ここまで)pathListDir, pathIsFile, pathIsDirectory (追記ここまで)
[ci skip]
VS2022: 17.6.33815.320 => 17.6.33829.357 [skip ci] This is an automated commit to keep track of toolchain changes on the build server. It applies to every MTA build after this commit until further notice.
VS2019: 16.11.33801.447 => 16.11.33920.266 [skip ci] This is an automated commit to keep track of toolchain changes on the build server. It applies to every MTA build after this commit until further notice.
[ci skip]
VS2019: 16.11.33927.289 => 16.11.34031.81 [skip ci] This is an automated commit to keep track of toolchain changes on the build server. It applies to every MTA build after this commit until further notice.
Build Tools 2022 (17.7.34031.279) This is an automated commit to keep track of toolchain changes on the build server. It applies to every MTA build after this commit until further notice. [skip ci]
Also refactored SharedUtil a little (`WIN32` might not be defined. `_WIN32` will always be defined)
Now `SharedUtil::ListDir` is crossplatform/crossservice
[skip ci]
For version control purposes
For version control purposes
For version control purposes, second-last one
...into 180923_Add-fileListDir
Cannot remove `#if __cplusplus >= 201703L` because client side code is using these functions (multiplayer_sa is c++14)
`WIN32_TESTING` was changed to `_WIN32_TESTING`. Changed back to the original definition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM :shipit:
There's been many code reviews, so merging.
@TracerDS thanks, please add it to wiki though
Uh oh!
There was an error while loading. Please reload this page.
Also refactored SharedUtil a little (
WIN32might not be defined._WIN32will always be defined)Syntax:
(削除)table fileListDir ( string path )(削除ここまで)table pathListDir ( string path )returns table of entries on success,
nilon failureAdditional functions
(削除)bool isFile ( string path )(削除ここまで)bool pathIsFile ( string path )Returns true if path is a file, false if a directory or path doesn't exist
(削除)bool isDirectory ( string path )(削除ここまで)bool pathIsDirectory ( string path )Returns true if path is a directory, false if a file or path doesn't exist
OOP functions
path.listDir=>pathListDirpath.isFile=>pathIsFilepath.isDirectory=>pathIsDirectoryResolves: #346