|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: May 2008
Messaggi: 412
|
[java] problemi con alcuni file e cartelle invisibili
Ciao a tutti,
volevo chiedervi come mai mentre cerco di visualizzare file e cartelle con il seguente codice: Codice:
File file=new File("C:\\"); File f[]=file.listFiles(); for(int i=0;i<f.length;i++){ if(!f[i].isHidden()){ System.out.println(f[i].getPath()); } } Codice:
if(!f[i].isHidden()) |
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: Oct 2007
Città: Padova
Messaggi: 4131
|
Sistema operativo?
Secondo la documentazione del metodo isHidden in java.io.File il fatto che un file sia hidden dipende da cosa il so/file system sottostante consideri come hidden. Prova a stampare a parte i file considerati hidden e confrontali con quelli che non sono considerati tali ma che tu ti aspetti lo siano.
__________________
As long as you are basically literate in programming, you should be able to express any logical relationship you understand. If you don’t understand a logical relationship, you can use the attempt to program it as a means to learn about it. (Chris Crawford) |
![]() |
![]() |
![]() |
#3 |
Senior Member
Iscritto dal: May 2008
Messaggi: 412
|
il sistema operativo è windows, ma cosa dovrei confrontare poi? per esempio la cartella Document and Settings è invisibile però viene stampata, poi c'è il file autoexec.bat che pure è invisibile.
|
![]() |
![]() |
![]() |
#4 | |
Senior Member
Iscritto dal: Nov 2005
Città: Texas
Messaggi: 1722
|
Quote:
C'era un bug di vecchia data, restato per quanto ne so, irrisolto: http://bugs.sun.com/view_bug.do?bug_id=5029353 Ce n'era anche un altro relativo al fatto che questo metodo sbagliava ancora quando il file era hidden e write-protected, ma non riesco a trovarlo
__________________
In God we trust; all others bring data |
|
![]() |
![]() |
![]() |
#5 |
Senior Member
Iscritto dal: May 2008
Messaggi: 412
|
non esiste un metodo in java per capire se un file o una cartella è di sistema?
|
![]() |
![]() |
![]() |
#6 | |
Senior Member
Iscritto dal: Nov 2005
Città: Texas
Messaggi: 1722
|
Quote:
http://stackoverflow.com/questions/1...system-os-file Puoi sempre girarci intorno: su internet ci sono dei siti che forniscono informazioni sui file di Windows/Linux (librerie condivise, ....). Potresti collegarti ad uno di loro automaticamente e verificare il file sotto esame
__________________
In God we trust; all others bring data |
|
![]() |
![]() |
![]() |
#7 |
Bannato
Iscritto dal: Mar 2008
Città: Villabate(PA)
Messaggi: 2515
|
Non è meglio scriversi una bella dll in C? Una funzioncina da richiamare tramite JNI?
![]() Bug irrisolto ![]() Nientedimeno dalla versione 4(e siamo alla 7) ![]() Ultima modifica di Vincenzo1968 : 12-03-2013 alle 12:36. |
![]() |
![]() |
![]() |
#8 | |
Senior Member
Iscritto dal: Nov 2005
Città: Texas
Messaggi: 1722
|
Quote:
![]() Certo che si puo' scrivere una funzioncina jni o javacpp. Si puo' sempre fare. C'e' chi pero' preferisce non farlo, per una pletora di motivi...
__________________
In God we trust; all others bring data |
|
![]() |
![]() |
![]() |
#9 |
Bannato
Iscritto dal: Mar 2008
Città: Villabate(PA)
Messaggi: 2515
|
Ah dunque, per via dell'antipatia che si ha verso il C, ci si tiene la versione buggata! LOL, SUPERLOL, SUPERMEGALOOOOOOOLLLLLLL!
![]() super ![]() super mega ![]() |
![]() |
![]() |
![]() |
#10 | |
Senior Member
Iscritto dal: Nov 2005
Città: Texas
Messaggi: 1722
|
Quote:
Se mi servisse la suddetta funzione, valuterei costi/benefici e potrei decidere di implementarla. Siamo tutti d'accordo che l'implementazione e' triviale. Ma si dice che la testa di quei signori sia visibile dallo spazio (non come la muraglia cinese), quindi avranno i loro buoni motivi
__________________
In God we trust; all others bring data |
|
![]() |
![]() |
![]() |
#11 |
Bannato
Iscritto dal: Mar 2008
Città: Villabate(PA)
Messaggi: 2515
|
EDIT: -
Ultima modifica di Vincenzo1968 : 12-03-2013 alle 22:11. Motivo: Sbagliato thread: era una altro thread su un altro forum in un altro sito. LOL!!! |
![]() |
![]() |
![]() |
#12 |
Senior Member
Iscritto dal: May 2008
Messaggi: 412
|
penso sarà per un fatto di sicurezza, resta il fatto però che comporta grossi limiti.
|
![]() |
![]() |
![]() |
#13 | |
Senior Member
Iscritto dal: Nov 2005
Città: Texas
Messaggi: 1722
|
Quote:
Comunque puoi sempre risolvere con una piccola jni.
__________________
In God we trust; all others bring data |
|
![]() |
![]() |
![]() |
#14 | |
Senior Member
Iscritto dal: Oct 2001
Messaggi: 11471
|
Quote:
Codice:
public boolean isHidden() { SecurityManager security = System.getSecurityManager(); if (security != null) { security.checkRead(path); } return ((fs.getBooleanAttributes(this) & FileSystem.BA_HIDDEN) != 0); } … public abstract int getBooleanAttributes(File f); … static private FileSystem fs = FileSystem.getFileSystem(); … public static native FileSystem getFileSystem(); Leggendo il bug report che hai postato poco sopra mi pare poi di leggere che anche il programma attrib di windows ha gli stesi problemi. Probabilmente quella parte di api ha una documentazione più oscena del solito. Se anche la stessa microsoft non è in grado di dirti se un file è nascosto c'è un grosso problema di fondo. |
|
![]() |
![]() |
![]() |
#15 |
Senior Member
Iscritto dal: May 2007
Città: Milano
Messaggi: 7103
|
Microsoft... Sempre una certezza!
Inviato dal mio Sony Xperia P
__________________
Apple Watch Ultra + iPhone 15 Pro Max + Rog Ally + Legion Go |
![]() |
![]() |
![]() |
#16 | |||
Senior Member
Iscritto dal: Nov 2005
Città: Texas
Messaggi: 1722
|
Quote:
Quote:
Quote:
@Prince_81 - utilizzando infatti il package java.nio.file, dovresti riuscire ad ottenere il flag corretto
__________________
In God we trust; all others bring data Ultima modifica di sottovento : 13-03-2013 alle 08:02. |
|||
![]() |
![]() |
![]() |
#17 | |
Senior Member
Iscritto dal: Oct 2007
Città: Padova
Messaggi: 4131
|
Quote:
![]()
__________________
As long as you are basically literate in programming, you should be able to express any logical relationship you understand. If you don’t understand a logical relationship, you can use the attempt to program it as a means to learn about it. (Chris Crawford) |
|
![]() |
![]() |
![]() |
#18 |
Bannato
Iscritto dal: Mar 2008
Città: Villabate(PA)
Messaggi: 2515
|
|
![]() |
![]() |
![]() |
#19 |
Bannato
Iscritto dal: Mar 2008
Città: Villabate(PA)
Messaggi: 2515
|
Codice:
// http://msdn.microsoft.com/it-it/library/windows/desktop/aa365200(v=vs.85).aspx #include <windows.h> #include <tchar.h> #include <stdio.h> #include <strsafe.h> #pragma comment(lib, "User32.lib") void DisplayErrorBox(LPTSTR lpszFunction); int _tmain(int argc, TCHAR *argv[]) { WIN32_FIND_DATA ffd; LARGE_INTEGER filesize; TCHAR szDir[MAX_PATH]; size_t length_of_arg; HANDLE hFind = INVALID_HANDLE_VALUE; DWORD dwError=0; // If the directory is not specified as a command-line argument, // print usage. if(argc != 2) { _tprintf(TEXT("\nUsage: %s <directory name>\n"), argv[0]); return (-1); } // Check that the input path plus 3 is not longer than MAX_PATH. // Three characters are for the "\*" plus NULL appended below. StringCchLength(argv[1], MAX_PATH, &length_of_arg); if (length_of_arg > (MAX_PATH - 3)) { _tprintf(TEXT("\nDirectory path is too long.\n")); return (-1); } _tprintf(TEXT("\nTarget directory is %s\n\n"), argv[1]); // Prepare string for use with FindFile functions. First, copy the // string to a buffer, then append '\*' to the directory name. StringCchCopy(szDir, MAX_PATH, argv[1]); StringCchCat(szDir, MAX_PATH, TEXT("\\*")); // Find the first file in the directory. hFind = FindFirstFile(szDir, &ffd); if (INVALID_HANDLE_VALUE == hFind) { DisplayErrorBox(TEXT("FindFirstFile")); return dwError; } // List all the files in the directory with some info about them. do { if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { _tprintf(TEXT(" %s <DIR>\n"), ffd.cFileName); } else { if ( !(ffd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ) { filesize.LowPart = ffd.nFileSizeLow; filesize.HighPart = ffd.nFileSizeHigh; _tprintf(TEXT(" %s %ld bytes\n"), ffd.cFileName, filesize.QuadPart); } } } while (FindNextFile(hFind, &ffd) != 0); dwError = GetLastError(); if (dwError != ERROR_NO_MORE_FILES) { DisplayErrorBox(TEXT("FindFirstFile")); } FindClose(hFind); return dwError; } void DisplayErrorBox(LPTSTR lpszFunction) { // Retrieve the system error message for the last-error code LPVOID lpMsgBuf; LPVOID lpDisplayBuf; DWORD dw = GetLastError(); FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL ); // Display the error message and clean up lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT, (lstrlen((LPCTSTR)lpMsgBuf)+lstrlen((LPCTSTR)lpszFunction)+40)*sizeof(TCHAR)); StringCchPrintf((LPTSTR)lpDisplayBuf, LocalSize(lpDisplayBuf) / sizeof(TCHAR), TEXT("%s failed with error %d: %s"), lpszFunction, dw, lpMsgBuf); MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK); LocalFree(lpMsgBuf); LocalFree(lpDisplayBuf); } ![]() Se commento la parte che dice di non mostrare i file nascosti: ![]() ![]() super ![]() super mega ![]() Ultima modifica di Vincenzo1968 : 13-03-2013 alle 13:14. |
![]() |
![]() |
![]() |
#20 | |
Bannato
Iscritto dal: Mar 2008
Città: Villabate(PA)
Messaggi: 2515
|
Quote:
Codice:
if ( !(ffd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ) { filesize.LowPart = ffd.nFileSizeLow; filesize.HighPart = ffd.nFileSizeHigh; _tprintf(TEXT(" %s %ld bytes\n"), ffd.cFileName, filesize.QuadPart); } ![]() super ![]() super mega ![]() |
|
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 04:03.