Extract file data from Raw View via script?
-
xboxninja
- Posts: 10
- Joined: 12 Feb 2010 15:10
- Location: New Jersey, USA
Extract file data from Raw View via script?
I'm pretty new to scripting so I thought I'd post the question to the experts since I didn't find anything that covered this topic previously.
Is it possible to use file data from the XYplorer Raw Data view in a script?
I wrote a script to pull files from my browser cache directories, prompt me for a new name (with extension) and copy them to various locations based on the new extension that the user types in. This is useful to copy cached audio, video or image files to my drive for "archiving purposes". However, since browsers store their cached files without an extension it's sometimes difficult to know exactly what the file type is. I can figure out the file type when I look at the Raw View for a given file so I'd like to incorporate this into my script; perhaps filling in the appropriate extension when the script prompts me for a new file name.
Any help would be greatly appreciated. Thanks!
- Don
Is it possible to use file data from the XYplorer Raw Data view in a script?
I wrote a script to pull files from my browser cache directories, prompt me for a new name (with extension) and copy them to various locations based on the new extension that the user types in. This is useful to copy cached audio, video or image files to my drive for "archiving purposes". However, since browsers store their cached files without an extension it's sometimes difficult to know exactly what the file type is. I can figure out the file type when I look at the Raw View for a given file so I'd like to incorporate this into my script; perhaps filling in the appropriate extension when the script prompts me for a new file name.
Any help would be greatly appreciated. Thanks!
- Don
-
admin
- Site Admin
- Posts: 66083
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: Extract file data from Raw View via script?
Hi,
currently not possible in a very elegant manner, but I will think about adding a command ReadFileBytes (or so) where you can specify the start position and number of bytes to read into a string.
Don
currently not possible in a very elegant manner, but I will think about adding a command ReadFileBytes (or so) where you can specify the start position and number of bytes to read into a string.
Don
FAQ | XY News RSS | XY X
-
xboxninja
- Posts: 10
- Joined: 12 Feb 2010 15:10
- Location: New Jersey, USA
Re: Extract file data from Raw View via script?
Thanks Don! I'd love to see a suggestion of mine incorporated into XYplorer!
I think this is possible with the exsting functions, though. "readfile" works pretty well! I played around with this for a few minutes and came up with the following code:
This seems to work - at least for the couple of file types I tested it on. If anyone has any further suggestions, I'd appreciate the input and assistance.
- Don
I think this is possible with the exsting functions, though. "readfile" works pretty well! I played around with this for a few minutes and came up with the following code:
Code: Select all
//read the contents of the selected file into $a
$a = readfile(<curitem>, b);
//just grab the first part of the file to find the headers
$b = substr($a, 0, 500);
//dump the hex values to a variable
$c = hexdump($b);
//look for certain file identifiers and display probably format
if (strpos($c, "flv") > 0)
{
echo "this is an flv file!";
} elseif (strpos($c, "ID3") > 0) {
echo "this is an mp3!";
} else {
echo "not sure what this is!";
}
- Don
-
admin
- Site Admin
- Posts: 66083
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: Extract file data from Raw View via script?
Yep, but with very large files you are wasting resources because readfile() reads the whole file.xboxninja wrote:Thanks Don! I'd love to see a suggestion of mine incorporated into XYplorer!
I think this is possible with the exsting functions, though. "readfile" works pretty well! I played around with this for a few minutes and came up with the following code:
This seems to work - at least for the couple of file types I tested it on. If anyone has any further suggestions, I'd appreciate the input and assistance.Code: Select all
//read the contents of the selected file into $a $a = readfile(<curitem>, b); //just grab the first part of the file to find the headers $b = substr($a, 0, 500); //dump the hex values to a variable $c = hexdump($b); //look for certain file identifiers and display probably format if (strpos($c, "flv") > 0) { echo "this is an flv file!"; } elseif (strpos($c, "ID3") > 0) { echo "this is an mp3!"; } else { echo "not sure what this is!"; }
- Don
FAQ | XY News RSS | XY X
-
SkyFrontier
- Posts: 2341
- Joined: 04 Jan 2010 14:27
- Location: Pasárgada (eu vou!)
Re: Extract file data from Raw View via script?
Off-topic but not that much:
xboxninja, can you please code something just to find and replace in a given .txt file?
(quoting from original thread:)
Please...?
Thank you!
xboxninja, can you please code something just to find and replace in a given .txt file?
(quoting from original thread:)
A section could be dedicated to manually (yeah, inside the script - nothing asking for anything, no GUI!) enter allowed values, and (of course!) another to manually enter a given expression to be searched and finally the expression to replace with. I want to assign such script onto a CTB (Custom Toolbar Button)/CKS (Custom Keyboard Shortcut) and have it ready to replace text expressions found on any number of selected files.What I have in mind is: select mixed text files (.txt and .ini, for instance) and applying a text replacing previously written inside the script - no prompts, just "select files - press CKS".
Please...?
Thank you!
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
-
xboxninja
- Posts: 10
- Joined: 12 Feb 2010 15:10
- Location: New Jersey, USA
Re: Extract file data from Raw View via script?
Yes, I just noticed that when I used this on a 120mb file. XYplorer was very quick to give back the memory though.admin wrote:Yep, but with very large files you are wasting resources because readfile() reads the whole file.
- Don
- Don
-
j_c_hallgren
- XY Blog Master
- Posts: 5826
- Joined: 02 Jan 2006 19:34
- Location: So. Chatham MA/Clearwater FL
- Contact:
Re: Extract file data from Raw View via script?
True, but as he wrote, he doesn't have much choice as the file in his browser cache have no extensions so he has to test them internally...that's why a command like you suggested (and as I posted in revived readfile thread) would help in this case.admin wrote:Yep, but with very large files you are wasting resources because readfile() reads the whole file.
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.
-
j_c_hallgren
- XY Blog Master
- Posts: 5826
- Joined: 02 Jan 2006 19:34
- Location: So. Chatham MA/Clearwater FL
- Contact:
Re: Extract file data from Raw View via script?
That was a bit off-topic...but anyway...as a suggestion for a way to do it: http://www.ecobyte.com/replacetext/SkyFrontier wrote:Off-topic but not that much:
xboxninja, can you please code something just to find and replace in a given .txt file?
I've used this for a few yrs and it proved extremely handy to change multiple strings in mutiple files in one pass...and strings that were a bit unusual as well...like line feeds, CR's and such which are hard to enter in some editors.
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.
-
SkyFrontier
- Posts: 2341
- Joined: 04 Jan 2010 14:27
- Location: Pasárgada (eu vou!)
Re: Extract file data from Raw View via script?
Thanks for the suggestion, Hallgren.
But I'd really want to avoid external apps doing the job while XY has internally the potential to solve the problem with a single keystroke.
Muroph's script serves well the purpose, but while he's off to do a simpler version... seems I'll have to pass the stuff to low prio.
(downloading to test, just in case... lol)
-I came across a portable tool which also support parameters, hope I remember the name of it to post here soon for the record. That was a GREAT candidate!
But I'd really want to avoid external apps doing the job while XY has internally the potential to solve the problem with a single keystroke.
Muroph's script serves well the purpose, but while he's off to do a simpler version... seems I'll have to pass the stuff to low prio.
(downloading to test, just in case... lol)
-I came across a portable tool which also support parameters, hope I remember the name of it to post here soon for the record. That was a GREAT candidate!
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
-
zer0
- Posts: 2676
- Joined: 19 Jan 2009 20:11
Re: Extract file data from Raw View via script?
Is it too short-sighted of me to think of the following sequence to do the trick for SkyFrontier?
1) Read in a file
2) Prompt for needle (string to search for)
3) Prompt for replacement
4) Stuff them into a replace scripting command and run it against a variable that holds data that has been read in
5) Call writefile to overwrite existing file
Is there a catch or it's really that easy?

1) Read in a file
2) Prompt for needle (string to search for)
3) Prompt for replacement
4) Stuff them into a replace scripting command and run it against a variable that holds data that has been read in
5) Call writefile to overwrite existing file
Is there a catch or it's really that easy?
Reporting a bug? Have a wish? Got a question? Use search - View roadmap - FAQs: Forum + XY site
Windows 7/10
Always using the latest stable two-decimal build
Windows 7/10
Always using the latest stable two-decimal build
-
j_c_hallgren
- XY Blog Master
- Posts: 5826
- Joined: 02 Jan 2006 19:34
- Location: So. Chatham MA/Clearwater FL
- Contact:
Re: Extract file data from Raw View via script?
Fo those type of operations, I'd probably do a write to a new file rather than overwrite so that results can be verified first...just the old way maybe but safer.
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.
-
zer0
- Posts: 2676
- Joined: 19 Jan 2009 20:11
Re: Extract file data from Raw View via script?
Sure, or one can just make a copy of a file and practice on that one. Either way, I jumped straight to the eventual command. I trust XY users to adhere to best practices when it comes to things like thatj_c_hallgren wrote:Fo those type of operations, I'd probably do a write to a new file rather than overwrite so that results can be verified first...just the old way maybe but safer.
Reporting a bug? Have a wish? Got a question? Use search - View roadmap - FAQs: Forum + XY site
Windows 7/10
Always using the latest stable two-decimal build
Windows 7/10
Always using the latest stable two-decimal build
-
SkyFrontier
- Posts: 2341
- Joined: 04 Jan 2010 14:27
- Location: Pasárgada (eu vou!)
Re: Extract file data from Raw View via script?
In case, this is what I'm talking about:
1) Read in a file.
2) DON'T prompt for needle (string to search for) - it's already inside the script both search/replacement strings.
3) DON'T prompt for replacement - just point and shoot.
4) Call writefile to overwrite existing file. Period.
Otherwise, we already have the great Text Replacer from Muroph:
http://www.xyplorer.com/xyfc/viewtopic. ... 7&start=15
and
http://www.xyplorer.com/xyfc/download/file.php?id=687
which is more sophisticated.
I'm thinking on the lower level possible - just do what the script tells. Extension checking would be great, but also user define-able, right inside the script.
1) Read in a file.
2) DON'T prompt for needle (string to search for) - it's already inside the script both search/replacement strings.
3) DON'T prompt for replacement - just point and shoot.
4) Call writefile to overwrite existing file. Period.
Otherwise, we already have the great Text Replacer from Muroph:
http://www.xyplorer.com/xyfc/viewtopic. ... 7&start=15
Code: Select all
"Text Replacer v1"
$sep=getkey(RegExpRenameSep,general);
end (getinfo(countselected)<1);
getkey $last,last,text_loop,"script_settings.ini";
$regex=input("Enter RegEx","<match>$sep<replace>,$last");
setkey $last,last,text_loop,"script_settings.ini";
$filelist = getinfo('SelectedItemsPathNames','|');
$count=1;
while(1){
$file=gettoken($filelist,$count,"|");
if("$file"==""){break;}
$match=gettoken($regex,1,$sep);
$rep=gettoken($regex,2,$sep);
$data=regexreplace(readfile($file),$match,$rep);
writefile($file,$data);
$count++;}
status "Done!",,ready;Code: Select all
text_rep3_beta.xyswhich is more sophisticated.
I'm thinking on the lower level possible - just do what the script tells. Extension checking would be great, but also user define-able, right inside the script.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
-
j_c_hallgren
- XY Blog Master
- Posts: 5826
- Joined: 02 Jan 2006 19:34
- Location: So. Chatham MA/Clearwater FL
- Contact:
Re: Extract file data from Raw View via script?
This thread has gone SO far afield of the original request that I suspect OP would prefer this be migrated to a separate thread...it had minimal connection to extracting a few fields from file and now has morphed into a text replacement so I think it would be best to isolate when possible these paths.
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.
-
SkyFrontier
- Posts: 2341
- Joined: 04 Jan 2010 14:27
- Location: Pasárgada (eu vou!)
Re: Extract file data from Raw View via script?
...which already exists.
So any updates on TEXT replacements, go there:
http://www.xyplorer.com/xyfc/viewtopic. ... 7&start=15
Or stay on this channel on extracting data out of raw view.
So any updates on TEXT replacements, go there:
http://www.xyplorer.com/xyfc/viewtopic. ... 7&start=15
Or stay on this channel on extracting data out of raw view.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
XYplorer Beta Club