如何使linux/macOS命令“ .ls>>文件.txt”使用 exec() 在 php 运行?
我只想列出所有文件和子目录并将此列表存储在文件中... 在 MS-DOS、Linux 和 MAC OS 中,命令行 -- .ls( 或 .dir) >> files.txt——会给我我想要的...... 但是,如何让 php 脚本运行它呢?
如果我使用(在 php 上)
exec ('ls >> files.txt');
我会收到这样的错误: 警告:输入中出现意外字符:第 29 行 /Applications/XAMPP/xamppfiles/htdocs/DjUtilities/makeLabels.php 中的 '' (ASCII=28) state=0
...
请问,有什么想法吗???
它的用途是为 CD 中的音乐设置标签,这里按目录划分...... 我想获取任何 cd(子目录)并列出文件(曲目)以使用曲目列表制作标签...
所以,最初的想法是使用这些数据创建一个文件,然后处理数据以制作标签...任何更好的方法都将非常受欢迎!
I Just wanna to list all files and subdirectories and store this list in file ...
in MS-DOS, Linux and MAC OS, the command line -- .ls( or .dir) >> files.txt -- would give me what I want ...
But, how to make a php script run it ?
if I use (on php)
exec ('ls >> files.txt');
I will get a error like this:
Warning: Unexpected character in input: '' (ASCII=28) state=0 in /Applications/XAMPP/xamppfiles/htdocs/DjUtilities/makeLabels.php on line 29
...
please, any idea ???
The use of this will be to set labels with the musics in a cd, here, divided by directories...
I wanna to get any cd's (subdirectories) and list the files (the tracks) to make a label with the track list....
So, The initial idea was to create a file with these data and then, process the data to make the labels... any better way to do that will be very welcome !!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用“opendir”和“readdir”来执行此操作,这两个都是本机 php 命令...
You can use 'opendir' and 'readdir' to do that, both native php commands...
这不取决于您的“exec(...)”代码。相同的代码在我的环境中运行良好。
这是结果。
所以,看起来你的 php 文件第 29 行可能有一些奇怪的语法/字符。(比如反斜杠的错误使用)
It's not up to your 'exec(...)' code. Same code runs well in my environment.
And It's result.
So, It looks like your php file may has some weird syntax/characters on line 29. ( like wrong usage of backslashes )