The command line
PHP Code:
[[dir /t:w "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:w "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:w "F:\my_file"]], 0)
guess it depends on the time of day
for Windows only
PHP Code:
function get_file_timestamp(file_name, dir) -- // 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
command, capt = '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
command, capt = 'forfiles /P '..dir..' /M "'..file_name..'" /C "cmd /c echo @fdate @ftime"', '.+\n(.+)\n' -- // excluding trailing empty line
end
return reaper.ExecProcess(command, 0):match(capt)
end
streamlined
PHP Code:
function get_file_timestamp(full_file_path) -- // timestamp with seconds
local dir, file_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
.
.