Hi folks,
I am a complete newb with XY scripting. I need to generate a tab separated text file of a huge number of G-office files distributed throughout a file system. As you probably know these files are actually just text files with different extensions.
I am trying to work with two functions - report() and readfile().
What I want is to get each line to have the full path, file name, date modified, and the contents of the file.
What I have done is create a query that gives me a listing of all the files. Then I manually ran the script report(readfile()), which successfully gave me all the contents -- but I don't know which one is which!
As soon as I start adding in the variables for the different fields, it breaks. As soon as I start putting in quotation marks I think it breaks the readfile() function... I think?
Let me know how I can make this work and I will be very appreciative!
Thanks.
Raw data in a report
Re: Raw data in a report
The fastest way to do this is using quicksearch() to find the necessary
files and provide all the required data (if you have a rather recent version of XYplorer!)
and then use readfile in a foreach loop for all files found to append the content to each line
E.g.:
files and provide all the required data (if you have a rather recent version of XYplorer!)
and then use readfile in a foreach loop for all files found to append the content to each line
E.g.:
Code: Select all
$paths = "D:\"; // Can be a ;-separated list of drives/paths
$extensions = "txt;bat"; // A ;-separated list of extensions for g-office
$data = quicksearch("/types=$extensions", $paths, , "sm") . <crlf>;
// Get only the full path + modified date
$data = regexreplace($data, "([^|]+)\|([^|]+)\|([^|]+)\|(.*?(?=\r?\n))", "$1|$3");
// Split the full path into path + file
$data = regexreplace($data, "(.*)\\([^|]+)\|(.*?(?=\r?\n))", "$1<tab>$2<tab>$3<tab>");
$report = "";
foreach($item, $data, <crlf>, "e") {
$file = regexreplace($item, "(.*?)<tab>(.*?)<tab>(.*)", "$1\$2");
$content = readfile($file);
$report = $report . $item . $content . <crlf>;
}
text $report;
One of my scripts helped you out? Please donate via Paypal
Re: Raw data in a report
So those g-office files have a single line of text?idheitmann wrote:What I want is to get each line to have the full path, file name, date modified, and the contents of the file.
This script assumes your query displays all found g-office files in the current list.
Code: Select all
$input = listpane(,, 1); // take currently listed items as input (as a |-separated filelist)
$output = "<xydata>\temp\g-office-report.log"; // generated report is writen to this file
setting "backgroundfileops", 0; delete 0, 0, $output; // clear any previous generated report
foreach ($file, $input) { // process each file
$report = report("{Fullpath}<tab>{Name}<tab>{Modified}<tab>" . readfile($file), $file);
writefile($output, $report, 'a'); // append report to output
}
openwith "notepad",, $output; // open output file in notepad
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
-
- Posts: 4
- Joined: 04 Mar 2015 18:38
Re: Raw data in a report
Awesome, thank you guys, I will let you know how it goes with these.
-
- Posts: 4
- Joined: 04 Mar 2015 18:38
Re: Raw data in a report
Ended up using SammaySarkar's script which worked flawlessly.
For posterity: yes, Google office files on the local drive are just text files with document ID's in them, single line.
I had to do a little bit of post-processing because the files are full of brackets and tags and quotation marks and stuff. A bit of find and replace yielded a text file I could easily import into Excel.
So thanks!
For posterity: yes, Google office files on the local drive are just text files with document ID's in them, single line.
I had to do a little bit of post-processing because the files are full of brackets and tags and quotation marks and stuff. A bit of find and replace yielded a text file I could easily import into Excel.
So thanks!