vb.net - Parse String to Date from a filename variable -
purpose move files in specified folders, in if date @ least day old today. i'm having trouble moving file since don't see archived. i'm assuming it's parsing date filename. vs2005 .net 2.0
sub copytoarchive(byval mydirpath) 'mydirpath = "c:\utresults\" 't:\utresults\press3\sv70206655\data07012015.txt example of txtfilelist dim txtfilelist string() = directory.getfiles(mydirpath, "*.txt", searchoption.alldirectories) 'search files in given path .txt type each txtname string in txtfilelist dim pressname string = txtname.substring(0, txtname.lastindexof("\")) 'take out file extension pressname = pressname.substring(0, pressname.lastindexof("\")) 'take out folder after press folder clean "press" pressname = pressname.remove(0, 13) dim folderexists string = path.combine("c:\writetest\", pressname) dim filename = txtname.remove(0, 4) filename = filename.substring(0, filename.lastindexof(".")) filename = convert.todatetime(filename) if filename < date.now if my.computer.filesystem.directoryexists(folderexists) my.computer.filesystem.movefile(txtname, folderexists) else my.computer.filesystem.createdirectory(folderexists) my.computer.filesystem.movefile(txtname, folderexists) end if end if next end sub
sub copytoarchive(byval mydirpath string) 'mydirpath = "c:\utresults\" 't:\utresults\press3\sv70206655\data07012015.txt example of txtfilelist dim dir new directoryinfo(mydirpath) dim fileinfos = dir.enumeratefiles("*.txt", searchoption.alldirectories) fileinfos = fileinfos. where(function(fi) datetime.parseexact(regex.replace(fi.name, "[^0-9]", ""), "mmddyyyy", nothing) < datetime.now.adddays(-1)) 'the magic here ------^^^ each info in fileinfos dim pressname string = _ path.getdirectoryname(info.directoryname).replace(mydirpath, "c:\writetest\") 'better/more efficient call createdirectory() every time my.computer.filesystem.createdirectory(pressname) my.computer.filesystem.movefile(info.fullname, pressname) next end sub
Comments
Post a Comment