B
Nachtrag:
Programm ist mittlerweile 3 mal im "Einsatz" gelaufen.
Eine tolle Sache. Jetzt nicht unbedingt wie es programmiert ist, das hatten wir ja schon.
Aber mich freut es ja tierisch, das ich es wenigstens(Wenn auch mit bescheidenen Mitteln) hinbekommen habe, mir die Sortierarbeit nicht mehr machen zu müssen. Jiha
Falls es jmd. interessieren sollte(glaub zwar nicht, aber vielleicht sieht ja jmd. noch was zu "verbessern" in diesem wohl Negativ-Beispiel), hier mal ein bisschen Code.
Ps.: Habe jetzt insgesamt 420 Mp3´s automatisch sortieren lassen. Wie geil :-))
Hier "lagere" ich mal in Powershell aus, erstelle die Skripts usw
#include <stdio.h>
#include <stdlib.h>
int init(void){
int dummy, dir_anzahl;
char *command={"Get-ChildItem -Filter *.mp3 -Name | Out-File musik.txt"} ;//{"Get-ChildItem -Filter *.mp3 -Name D:\\_ext | Out-File D:\\_ext\\musik.txt"};
char *sys_cmd={"powershell %CD%\\c1"};
char *command2={"dir -Exclude *.* -Name O:\\Musik\\0_SETS_0 | sort-object name| Out-File referenz.txt "};
char *dir_cmd={"powershell %CD%\\c2"};
FILE *shell_dat, *dir_dat;
FILE *dump;
FILE *connect;
//check connection to EXT
if ( (connect=fopen("O:\\connect.itf", "w")) == NULL){
puts("Error...EXT-HDD Not CONNECTED!!!!");
system("pause");
exit(0);
}
else{
fclose(connect);
puts("HDD Connected, del itf-file");
if ( (remove("O:\\connect.itf")) != 0 ){
puts("Error deleting Connection File!!");
system("Pause");
exit(0);
}
}
if ( (dump=fopen("0000.mp3", "w")) == NULL){
puts("Error Creating Dump MP3!!!");
system("pause");
exit(0);
}
puts("Dump Created!!!\n");
fclose(dump);
// Read in the MP3 Directory => Create Skript
if ( (shell_dat=fopen("c1.ps1", "w")) == NULL){ //in current directory!!!
puts("Error Creating Reading Script File");
system("Pause"),
exit(0);
}
fprintf( shell_dat, command);
fclose(shell_dat);
// run the 1st script
if ( (dummy=system(sys_cmd)) !=0){
puts("Error with the 1st Script!!!");
system("Pause");
exit(0);
}
puts("MP3's Sucsessfully READ IN!!!\n");
// Create the 2nd script
if ( (dir_dat=fopen("c2.ps1", "w")) == NULL){ //in current directory!!!
puts("Error Creating 2nd Skript!!!");
system("Pause");
exit(0);
}
fprintf(dir_dat, command2);
fclose(dir_dat);
// run the 2nd script
dummy=0;
if ( (dummy=system(dir_cmd)) != 0 ){
puts("Error with teh 2nd Script!!!!");
system("Pause");
exit(0);
}
puts("Directory Sucsesfully READ IN!!!\n");
// Everything is fine, del the Scripts
remove("c1.ps1");
remove("c2.ps1");
remove("0000.mp3");
puts("Scripts & Dump Cleaned!!");
puts("now... Cleaing the Ref File of Dirs....\n");
dir_anzahl=clean_ref(); // Read the Directorys from the EXT-HDD !!!!!
if (dir_anzahl==0){
puts("Error on Cleaning the DIRS!!!!");
system("Pause");
exit(0);
}
puts("\n....done\n");
remove("referenz.txt");
puts("\n.......refernz.txt deleted......\n");
return dir_anzahl;
}
Hier wird gesucht und dann kopiert...
#include <stdio.h>
#include <stdlib.h>
#include "sys.h"
#define max 75
void search (MP3 *fptr, int ri_fil, int dir_anzahl){
FILE *dptr;
char buffer[max];
int i,j, copy_ct=0;
MP3 *sptr;
if ( (dptr=fopen("dirs.cl", "r")) == NULL ){
puts("Error on opening dirs.cl");
exit(0);
}
printf("%d - Files must be searched\n", ri_fil);
system("color 2");
for(i=2; i<dir_anzahl; i++){
fread(buffer, sizeof(DIRS), 1, dptr);
puts("\n");
puts(":::::::::::::::::::::::::::::::::::::");
puts(buffer);
puts("=>will be searched now");
puts("::::::::::::::::::::::::::::::::::::::");
sptr=fptr; //the Search Pointer
for(j=0; j<ri_fil; j++){
puts(buffer);
puts(sptr->id);
if ( strcmp(buffer, sptr->id) == 0){
puts("Matching Item Found!!!");
puts("try to copy....");
ccmd(sptr);
copy_ct++;
}
sptr++;
}
}
printf("%d Files kopiert!!!\n", copy_ct);
system("pause");
fclose(dptr);
}
Die "fiffelige" Arbeit war aber die Strings "passend" zu bekommen.
Hier die MP3 Dateinamen aus dem Powershell Skript:
#include <stdio.h>
#include <stdlib.h>
#include "sys.h"
#define max 150
#define _MAXMP3 150
void clean(int dir_anzahl){
//Var
FILE *szg, *ref;
int i, j, k, trenn, t_copy, dummy;
size_t len1, read_in=0;
char sbuffer[max], dbuffer[max-50], idbuffer[max-75], *read, *show;
MP3 log [_MAXMP3], *sptr , *hsptr ;
//End_Var
if ( (szg=fopen("musik.txt", "r")) == NULL){
puts("Error Opening Source File");
system("pause");
exit(0);
}
sptr=log;
fgets(sbuffer, max, szg); //read the first Entry. It is DUMP!!! 4get it
do {
read=fgets(sbuffer, max, szg); // Here the "Real" reading starts
j=0;
for(i=1; i<max; i+=2){ // Clean the Garbige Bytes between the Letters
dbuffer[j]=sbuffer[i];
j++;
}
for (k=0; k<max; k++){ // search the .mp3 chars
if ( dbuffer[k]=='.' && dbuffer[k+1]=='m' && dbuffer[k+2]=='p'){
dbuffer[k+4]='\0'; //Terminate the String
}
}
strcpy(sptr->filename, dbuffer); // Filename now in struct
len1=strlen(sptr->filename);
for (trenn=0; trenn < len1; trenn++){ //Get the ID(interpret) of the File
if ( dbuffer[trenn] == '-' ){
for (t_copy=0; t_copy < (trenn-1); t_copy++){
idbuffer[t_copy]=dbuffer[t_copy];
idbuffer[t_copy+1]='\0';
}
}
}
strcpy(sptr->id, idbuffer);
sptr++;
read_in++;
} while (read!=NULL);
read_in-=2; // one is the dump, one is the 0 of the array . ... is ok so
printf("%d Files eingelesen\n", read_in);
fclose(szg);
search(log, read_in, dir_anzahl); //now compare the Directorys with the Buffer-ID-s
Wer bis jetzt noch nicht gekot... hat, möge es jetzt tun, ich find´s trotzdem irgendwie toll ;-))
OT:
Allerdings bieten diese beiden Sprachen schon deutlich mehr Möglichkeiten eine elegante Bibliothek zu implementieren, welche es dir auf recht bequeme Art und Weise erlaubt Dateien zu kopieren/verschieben.
Ich muss mich jetzt dann beruflich mal ein bisschen mit C# beschäftigen... (Scheinbar kann man bei Siemens jetzt mit C# ein bisschen "Skripten"...)...
Welche Bibliotheken aus dem Zitat wären da evtl. für Dateiarbeit erwähnenswert?