Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Script to find file types and info Post 303039874 by Neo on Wednesday 16th of October 2019 08:49:02 PM
Old 10-16-2019
If you only need the file names, with PHP you can use scandir() to scan the entire web directory and put all the file names in array and filter the array based on the extensions. However, if you need more info than just the filename / extension, scandir() will not provide the ownership and permissions, information.

In that case, if I was doing this, I would simply exec() a variation of the ls -lR comand in a PHP script and put each entry (file information) into an array, and then filter the array as needed.

Of course, you don't need PHP to do this, but since your are using a web server which has PHP already, you might enjoy taking the output (your file inventory) and displaying your inventory results on a web page in addition to a CSV file Smilie


See also PHP: fputcsv()

Code:
fputcsv ( resource $handle , array $fields [, string $delimiter = "," [, string $enclosure = '"' [, string $escape_char = "\\" ]]] ) : int

Quote:
fputcsv() formats a line (passed as a fields array) as CSV and writes it (terminated by a newline) to the specified file handle.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

find directory with 2 types of files

Trying to use the find command to find any directory which contains a file ending in .zip AND a file ending in .o I'm having trouble specifying multiple files as criteria and have can't seem to figure it out from Unix in a Nutshell and Google. (2 Replies)
Discussion started by: dangral
2 Replies

2. Shell Programming and Scripting

find multiple file types and tar

There are these ksh files and config files that are written and updated on a daily basis. All I want to do is write a script that finds both these types of files and archive them on a daily basis, to help in restoring in times of system outages and so on. Particulary I'm interested in .ksh ,... (9 Replies)
Discussion started by: manthasirisha
9 Replies

3. Shell Programming and Scripting

trying to write a script to loop through a port info file

Below is part of a script i have written to loop through part of a port info file. How do i continue the script to get info for OS Device Name, manufacturer and then put information into an array? HBA Port WWN: 10000000c9420b4b OS Device Name: /dev/cfg/c10 Manufacturer: Emulex... (5 Replies)
Discussion started by: rcon1
5 Replies

4. Linux

Simplified find command to find multiple file types

Hi, I'm using the following command to find the multiple requierd file types and its working fine find . -name "*.pl" -o -name "*.pm" -o -name "*.sql" -o -name "*.so" -o -name "*.sh" -o -name "*.java" -o -name "*.class" -o -name "*.jar" -o -name "*.gz" -o -name "*.Z" -type f Though... (2 Replies)
Discussion started by: vickramshetty
2 Replies

5. Shell Programming and Scripting

How to pass multiple file types search pattern as argument to find?

How can I pass $var_find variable as argment to find command? test.sh var_find=' \( -name "*.xml" -o -name "*.jsp" \) ' echo "${var_find}" find . -type f ${var_find} -print # Below statement works fine.. I want to replace this with the above.. #find . \( -name "*.xml" -o -name... (4 Replies)
Discussion started by: kchinnam
4 Replies

6. UNIX for Dummies Questions & Answers

How to find the partition types in linux

How do we find the partition type in Linux? df -T will give me the mounted partition types like ufs, ext3 etc. How do I find out for say a newly added disk to the system? Please advise... Thanks (2 Replies)
Discussion started by: lubu
2 Replies

7. Shell Programming and Scripting

bash: find multiple types[solved]

Hi, I would like to use find to search for multiple types. For example search for symlink and regular file but not directories, sockets etc.... Something like: find . -type l,f -name "stuff" But of course it does not work. Is there any way to avoid an if statement and to do it faster? ... (0 Replies)
Discussion started by: Dedalus
0 Replies

8. Shell Programming and Scripting

Script to loop line in a file and add info or do echo

I have a record.txt it will update weekly, and it could be 2 lines or more ... it just echo each line to the script san jose,23.34% tampa,2.15% dallas,30.20% seattle,44.29% Unknown,16.72% How do i write a shell script to give me a test.pl or bash file which contain #!/home/perl... (8 Replies)
Discussion started by: sabercats
8 Replies

9. Shell Programming and Scripting

Using a single "find" cmd to search for multiple file types and output individual files

Hi All, I am new here but I have a scripting question that I can't seem to figure out with the "find" cmd. What I am trying to do is to only have to run a single find cmd parsing the directories and output the different file types to induvidual files and I have been running into problems.... (3 Replies)
Discussion started by: swaters
3 Replies

10. Shell Programming and Scripting

Backup script with selective file types only

i am looking for a backup script to be run in ssh which can move all *.php files only to a archive Eg. a folder has 5 sub folders with different file types, which can be mix of PDF, jpeg, gif etc etc. but the archive generated should only include the *.php files without breaking the directory... (3 Replies)
Discussion started by: netatma
3 Replies
SPLFILEOBJECT(3)							 1							  SPLFILEOBJECT(3)

The SplFileObject class

INTRODUCTION
The SplFileObject class offers an object oriented interface for a file. CLASS SYNOPSIS
SplFileObject SplFileObjectextends SplFileInfoRecursiveIteratorSeekableIterator Constants o const integer$SplFileObject::DROP_NEW_LINE1 o const integer$SplFileObject::READ_AHEAD2 o const integer$SplFileObject::SKIP_EMPTY4 o const integer$SplFileObject::READ_CSV8 Methods o public SplFileObject::__construct (string $filename, [string $open_mode = "r"], [bool $use_include_path = false], [resource $con- text]) o public string|array SplFileObject::current (void ) o public bool SplFileObject::eof (void ) o public bool SplFileObject::fflush (void ) o public string SplFileObject::fgetc (void ) o public array SplFileObject::fgetcsv ([string $delimiter = ","], [string $enclosure = " o public string SplFileObject::fgets (void ) o public string SplFileObject::fgetss ([string $allowable_tags]) o public bool SplFileObject::flock (int $operation, [int &$wouldblock]) o public int SplFileObject::fpassthru (void ) o public int SplFileObject::fputcsv (array $fields, [string $delimiter = ","], [string $enclosure = '"'], [string $escape = " o public string SplFileObject::fread (int $length) o public mixed SplFileObject::fscanf (string $format, [mixed &$...]) o public int SplFileObject::fseek (int $offset, [int $whence = SEEK_SET]) o public array SplFileObject::fstat (void ) o public int SplFileObject::ftell (void ) o public bool SplFileObject::ftruncate (int $size) o public int SplFileObject::fwrite (string $str, [int $length]) o public void SplFileObject::getChildren (void ) o public array SplFileObject::getCsvControl (void ) o public int SplFileObject::getFlags (void ) o public int SplFileObject::getMaxLineLen (void ) o public bool SplFileObject::hasChildren (void ) o public int SplFileObject::key (void ) o public void SplFileObject::next (void ) o public void SplFileObject::rewind (void ) o public void SplFileObject::seek (int $line_pos) o public void SplFileObject::setCsvControl ([string $delimiter = ","], [string $enclosure = " o public void SplFileObject::setFlags (int $flags) o public void SplFileObject::setMaxLineLen (int $max_len) o public void SplFileObject::__toString (void ) o public bool SplFileObject::valid (void ) Inherited methods o public SplFileInfo::__construct (string $file_name) o public int SplFileInfo::getATime (void ) o public string SplFileInfo::getBasename ([string $suffix]) o public int SplFileInfo::getCTime (void ) o public string SplFileInfo::getExtension (void ) o public SplFileInfo SplFileInfo::getFileInfo ([string $class_name]) o public string SplFileInfo::getFilename (void ) o public int SplFileInfo::getGroup (void ) o public int SplFileInfo::getInode (void ) o public string SplFileInfo::getLinkTarget (void ) o public int SplFileInfo::getMTime (void ) o public int SplFileInfo::getOwner (void ) o public string SplFileInfo::getPath (void ) o public SplFileInfo SplFileInfo::getPathInfo ([string $class_name]) o public string SplFileInfo::getPathname (void ) o public int SplFileInfo::getPerms (void ) o public string SplFileInfo::getRealPath (void ) o public int SplFileInfo::getSize (void ) o public string SplFileInfo::getType (void ) o public bool SplFileInfo::isDir (void ) o public bool SplFileInfo::isExecutable (void ) o public bool SplFileInfo::isFile (void ) o public bool SplFileInfo::isLink (void ) o public bool SplFileInfo::isReadable (void ) o public bool SplFileInfo::isWritable (void ) o public SplFileObject SplFileInfo::openFile NULL ([string $open_mode = "r"], [bool $use_include_path = false], [resource $context]) o public void SplFileInfo::setFileClass ([string $class_name = "SplFileObject"]) o public void SplFileInfo::setInfoClass ([string $class_name = "SplFileInfo"]) o public void SplFileInfo::__toString (void ) PREDEFINED CONSTANTS
o SplFileObject::DROP_NEW_LINE -Drop newlines at the end of a line. o SplFileObject::READ_AHEAD -Read on rewind/next. o SplFileObject::SKIP_EMPTY -Skips empty lines in the file. This requires the READ_AHEAD flag be enabled, to work as expected. o SplFileObject::READ_CSV -Read lines as CSV rows. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.3.9 | | | | | | | | | | SplFileObject::SKIP_EMPTY value changed to 4. | | | Previously, value was 6. | | | | +--------+---------------------------------------------------+ PHP Documentation Group SPLFILEOBJECT(3)
All times are GMT -4. The time now is 03:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy