Save Date & Time

Title SaveDateTime
File Names SaveDateTime.txt
Description Save creation and modification date and time of files specified to file
Author Vochomurka
Parameters ("%L", "%P")
Plugins Called file
Icon
Version 1.0
Updated on 29.01.2006
local InFile = file.open(arg(1), "r")
local OutName = arg(2) ++ "_NameDateFile.lst"
local OutFile = file.open(OutName, "w")
local Str, Counter, List, i, Date, Time, Temp
flag clear 1

if(InFile > 0) do
	for(not(file.eof(InFile))) 
		Str = file.readstring(InFile)
		if(Str != 0)
			Counter = Counter + 1

	endfor
else
	messagebox("ok error", "File not opened", "FILE plugin error #1")
	quit
endif

if(OutFile <= 0) do
	messagebox("ok error", "File not opened", "FILE plugin error #2")
	quit
endif

if(Counter == 1) do
	List = file.listfiles(arg(2), 0, 0)
	Counter = line(List, 0)
	flag set 1
else
	file.restart(InFile)
endif

for(i = 0; i < Counter; i = i + 1)
	if(pproflag(1)) do
		Str = line(List, i + 1)
	else
		Str = file.readstring(InFile)
	endif
	if(Str == OutName)
		jump Next

	file.writeline(OutFile, file.nametype(Str))
	Temp = file.getdate(Str, "c")
	Date = select(Temp, 8)
	file.writeline(OutFile, Date)
	Time = select(Temp, 9, 14)
	file.writeline(OutFile, Time)
	Temp = file.getdate(Str, "m")
	Date = select(Temp, 8)
	file.writeline(OutFile, Date)
	Time = select(Temp, 9, 14)
	file.writeline(OutFile, Time)
@Next
endfor

file.close(InFile)
file.close(OutFile)

Comments:

These two scripts realize the more general approach to assigning the creation and modification date/time of one file to another. Other scripts for particular cases are CopyDate and BatchCopyDate.

The SaveDateTime script saves date/time of files selected to file _NameDateFile.lst located in the current directory. There is no need to edit the resulting file.

Files to save their date/time can be selected before running the script. If no group is selected, then all files in the current directory are processed.


Load Date & Time

Title LoadDateTime
File Names LoadDateTime.txt
Description Restore creation and modification date and time from list file and assign them to files specified
Author Vochomurka
Parameters ("%L", "%P")
or
("%L", "%P", "full_file_path")
Plugins Called file, vec
Icon
Version 1.0
Updated on 29.01.2006
local InFile = file.open(arg(1), "r")
local OutName = ifelse(arg(0) == 2, arg(2) ++ "_NameDateFile.lst", arg(3))

if(file.validpath(OutName) != 1) do
	messagebox("ok error", "Invalid file path " ++ OutName, "FILE plugin error #1")
	quit
endif

local OutFile = file.open(OutName, "r")
local Str, Counter, List, i, j, Date, Time, Temp, Rex
flag clear 1

if(InFile > 0) do
	for(not(file.eof(InFile))) 
		Str = file.readstring(InFile)
		if(Str != 0)
			Counter = Counter + 1

	endfor
else
	messagebox("ok error", "File not opened", "FILE plugin error #3")
	quit
endif

if(Counter == 1) do
	List = file.listfiles(arg(2), 0, 0)
	Counter = line(List, 0)
	flag set 1
else
	file.restart(InFile)
endif

if(OutFile > 0) do
	for(not(file.eof(OutFile))) 
		Str = file.readstring(OutFile)
		if(Str != 0) do
			Rex = Rex + 1
		endif
	endfor
else
	messagebox("ok error", "File not opened", "FILE plugin error #3")
	quit
endif

if(Rex % 3 != 0) do
	Str = "File " ++ OutName ++ " seems to be corrupted"
	messagebox("ok error", Str, "LoadDateTime Script")
	quit
endif

DT = vec.create(Rex)
if(DT == 0) do
	messagebox("ok error", "Vector not created", "VEC plugin error")
	quit
endif

file.restart(OutFile)

for(i = 0; i < Rex; i = i + 1)
	Str = file.readstring(OutFile)
	if(Str != 0)
		DT[i] = Str

endfor

file.close(OutFile)

for(i = 0; i < Counter; i = i + 1)
	if(pproflag(1)) do
		Str = line(List, i + 1)
	else
		Str = file.readstring(InFile)
	endif
	if(Str == OutName)
		jump Next

	for(j = 0; j < Rex; j = j + 1)
		Temp = arg(2) ++ DT[j]
		if(file.validpath(Temp) == 1 && Temp == Str) do
			Date = DT[j + 1]
			Time = DT[j + 2]
			file.setdate(Str, "c", Date, Time)
			Date = DT[j + 3]
			Time = DT[j + 4]
			file.setdate(Str, "m", Date, Time)
			break
		endif
	endfor

@Next
endfor

file.close(InFile)
vec.unload

Comments:

This script restores date/time of file(s) from the list file created by the SaveDateTime script. If the LoadDateTime script has two parameters, then the list file named _NameDateFile.lst must be located in the current directory. If the third parameter is present, it must be the full name of the list file.

Files to restore date/time for are selected like for SaveDateTime script: if some files are selected into group, then only these files will be processed. If no files are selected, then all the files in the current directory will be processed.


Main Page Total Commander PowerPro