BianConiglio
15-03-2004, 09:13
Ho un immagine...ma voglio che un programma in automatico la cerchi nel mio hd e la sostituisca con una piu aggiornata che è contenuta nell' exe stesso..
vorrei che il mio prog:
Creasse l'immagine NEW.jpg in C:\ ( lo so fare )
Cercasse il file OLD.jpg nel disco ( non lo so fare )
Sostituisse il file OLD.jpg con NEW.jpg ( non lo so fare, perchè non so come trovare la path )
Cancellasse il file NEW.jpg che non mi interessa più dato che OLD.jpg ormai è bello che upgradato.
Ho cercato di farlo in diversi modi ma la ricerca ricorsiva o non mi funziona o mi funziona a metà...
Avete qualche sorgente con una ricerca del genere ?? in C..
:oink: azzie
io ho fatto
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
//Ricerca di un File by BianConiglio//
int _look4aFile (char* _strStartPath)
{
HANDLE _hFileSearch;
WIN32_FIND_DATA _hFileSearchData;
int lastError = 0;
char* _currentSearchPattern = (char*) malloc( MAX_PATH );
char* _reservedBuffer;
if (_currentSearchPattern)
{
if (!_strStartPath)
_strStartPath = "C:\\";
strcpy (_currentSearchPattern, _strStartPath);
strcat (_currentSearchPattern, "*");
if ( (_hFileSearch = FindFirstFile(_currentSearchPattern, &_hFileSearchData)) != INVALID_HANDLE_VALUE )
{
do {
if ( strcmp(_hFileSearchData.cFileName, ".") && strcmp(_hFileSearchData.cFileName, "..") )
{
if ( _hFileSearchData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY ) {
_reservedBuffer = (char*) malloc( MAX_PATH+1 );
if ( _reservedBuffer )
{
strcpy (_reservedBuffer, _strStartPath);
strcat (_reservedBuffer, _hFileSearchData.cFileName);
strcat (_reservedBuffer, "\\");
lastError = _look4aFile (_reservedBuffer);
free (_reservedBuffer);
} else
lastError = -1;
} else {
if ( !strcmp(_hFileSearchData.cFileName, "prova.txt" ))
printf ("Ho trovato un file \"%s\" nella cartella \"%s\"\n", _hFileSearchData.cFileName, _strStartPath);
}
}
}
while ( FindNextFile(_hFileSearch, &_hFileSearchData) );
} else
lastError = 1;
free (_currentSearchPattern);
FindClose (_hFileSearch);
} else
lastError = -1;
return lastError;
}
int main()
{
_look4aFile (NULL);
system("PAUSE");
return 0;
}
però dio santo funziona random.....da me funziona sempre.. su altri pc non scanna certe cartelle random....ha comportamenti diversi anche su sitemi con lo stesso sitema operatovo :(
che faccio ??
vorrei che il mio prog:
Creasse l'immagine NEW.jpg in C:\ ( lo so fare )
Cercasse il file OLD.jpg nel disco ( non lo so fare )
Sostituisse il file OLD.jpg con NEW.jpg ( non lo so fare, perchè non so come trovare la path )
Cancellasse il file NEW.jpg che non mi interessa più dato che OLD.jpg ormai è bello che upgradato.
Ho cercato di farlo in diversi modi ma la ricerca ricorsiva o non mi funziona o mi funziona a metà...
Avete qualche sorgente con una ricerca del genere ?? in C..
:oink: azzie
io ho fatto
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
//Ricerca di un File by BianConiglio//
int _look4aFile (char* _strStartPath)
{
HANDLE _hFileSearch;
WIN32_FIND_DATA _hFileSearchData;
int lastError = 0;
char* _currentSearchPattern = (char*) malloc( MAX_PATH );
char* _reservedBuffer;
if (_currentSearchPattern)
{
if (!_strStartPath)
_strStartPath = "C:\\";
strcpy (_currentSearchPattern, _strStartPath);
strcat (_currentSearchPattern, "*");
if ( (_hFileSearch = FindFirstFile(_currentSearchPattern, &_hFileSearchData)) != INVALID_HANDLE_VALUE )
{
do {
if ( strcmp(_hFileSearchData.cFileName, ".") && strcmp(_hFileSearchData.cFileName, "..") )
{
if ( _hFileSearchData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY ) {
_reservedBuffer = (char*) malloc( MAX_PATH+1 );
if ( _reservedBuffer )
{
strcpy (_reservedBuffer, _strStartPath);
strcat (_reservedBuffer, _hFileSearchData.cFileName);
strcat (_reservedBuffer, "\\");
lastError = _look4aFile (_reservedBuffer);
free (_reservedBuffer);
} else
lastError = -1;
} else {
if ( !strcmp(_hFileSearchData.cFileName, "prova.txt" ))
printf ("Ho trovato un file \"%s\" nella cartella \"%s\"\n", _hFileSearchData.cFileName, _strStartPath);
}
}
}
while ( FindNextFile(_hFileSearch, &_hFileSearchData) );
} else
lastError = 1;
free (_currentSearchPattern);
FindClose (_hFileSearch);
} else
lastError = -1;
return lastError;
}
int main()
{
_look4aFile (NULL);
system("PAUSE");
return 0;
}
però dio santo funziona random.....da me funziona sempre.. su altri pc non scanna certe cartelle random....ha comportamenti diversi anche su sitemi con lo stesso sitema operatovo :(
che faccio ??