Old 10-17-2021, 01:28 PM   #1
Buy One
Human being with feelings
 
Buy One's Avatar
 
Join Date: Sep 2019
Posts: 1,146
Default A: Using ExecProcess() to get file time stamp

The command line

PHP Code:
[[dir /t:"F:\my_file"]] 

works in io.popen() returning file handle but doesn't in ExecProcess() returning nil

Tried

PHP Code:
[[cmd.exe /C dir /t:"F:\my_file"]] 
which returns code 259

In both cases it's vividly launches the command (its window flashes) but nothing useful is returned

__________________________________________________ _

UPD:

As some say, take counsel of your pillow (not sure how idiomatic it is), but today this works

PHP Code:
reaper.ExecProcess([[cmd.exe /C dir /t:"F:\my_file"]], 0
guess it depends on the time of day


for Windows only

PHP Code:
function get_file_timestamp(file_namedir) -- // both args are strings; dir MUST NOT end with separator, if dir isn't provided file arg must be full path
local command
local capt
    
if not dir then -- // time without seconds
    
commandcapt 'cmd.exe /C dir \tw "'..file_name..'"''.+\n(.-%d+:%d+)'
    
return reaper.ExecProcess('cmd.exe /C dir \tw "'..file_name..'"'0):match('.+\n(.-%d+:%d+)')
    else -- 
// time with seconds
    
local dir #dir > 3 and dir:match('.+[\\/]$') and dir:match('(.+)[\\/]') or dir -- // remove last separator if any in dir other than the root
    
local dir #dir == 3 and dir or '"'..dir..'"' -- when not root as root doesn't allow quotes
    
commandcapt 'forfiles /P '..dir..' /M "'..file_name..'" /C "cmd /c echo @fdate @ftime"''.+\n(.+)\n' -- // excluding trailing empty line
    
end
return reaper.ExecProcess(command0):match(capt)
end 
streamlined

PHP Code:
function get_file_timestamp(full_file_path) -- // timestamp with seconds
local dirfile_name full_file_path:match('(.+)[\\/](.+)') -- // makes sure that dir doesn't end with separator
local dir #dir == 3 and dir or '"'..dir..'"' -- // when not root as root doesn't allow quotes
return reaper.ExecProcess('forfiles /P '..dir..' /M "'..file_name..'" /C "cmd /c echo @fdate @ftime"'0):match('.+\n(.+)\n') -- // excluding trailing empty line
end 
and thanks to cfillion for his replies on the forum, otherwise i wouldn't know where to start
.
.

Last edited by Buy One; 10-28-2021 at 03:13 AM.
Buy One is offline   Reply With Quote
Old 10-18-2021, 02:34 AM   #2
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,458
Default

You could use:
Quote:
retval, size, accessedTime, modifiedTime, cTime, deviceID, deviceSpecialID, inode, mode, numLinks, ownerUserID, ownerGroupID = reaper.JS_File_Stat( filePath )
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 10-18-2021, 03:46 AM   #3
Buy One
Human being with feelings
 
Buy One's Avatar
 
Join Date: Sep 2019
Posts: 1,146
Default

Quote:
Originally Posted by amagalma View Post
You could use:
Thank you, didn't notice the function, although i strive to avoid dependencies.
Buy One is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 06:07 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.