-
Notifications
You must be signed in to change notification settings - Fork 0
/
OpenSongTildessWindows.cpp
114 lines (88 loc) · 2.73 KB
/
OpenSongTildessWindows.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* File: main.cpp
* Author: LANCHAS
*
* Created on 30 de octubre de 2011, 21:19
*/
#include <fstream>
#include <iostream>
#include <string>
#include <map>
#include <cstdlib>
#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <windows.h>
using namespace std;
/*
*
*/
#define MAXPATHLEN 200
int main()
{
string dir, filepath;
char * dirbuf = new char[ MAXPATHLEN ]; dirbuf[ 0 ] = 0;
DIR *dp = NULL;
struct dirent *dirp;
struct stat filestat;
map <int, string> dictionary;
dictionary[-31] = "a"; // á
dictionary[-63] = "A"; // Á
dictionary[-23] = "e"; // é
dictionary[-55] = "E"; // É
dictionary[-24] = "e"; // è
dictionary[-56] = "E"; // È
dictionary[-19] = "i"; // í
dictionary[-51] = "I"; // Í
dictionary[-13] = "o"; // ó
dictionary[-45] = "O"; // Ó
dictionary[-6 ] = "u"; // ú
dictionary[-38] = "U"; // Ú
dictionary[-15] = "n"; // ñ
dictionary[-47] = "N"; // Ñ
// IMPORTANT: IF WRONG DOES NOT WORK
// getcwd (dirbuf, MAXPATHLEN); // UNIX
GetCurrentDirectory( MAXPATHLEN - 1, dirbuf ); // where are we working?
dp = opendir( dirbuf ); // open current directory
if (dp == NULL) exit(0);
dir = string(dirbuf);
delete dirbuf;
string newdir = dir + "\\acentos"; // modified files
mkdir(newdir.c_str(), 0777 );
//CreateDirectory(newdir.c_str(), NULL ); // windows
cout << "DIRECTORIO CREADO: " << newdir << endl;
while ((dirp = readdir( dp )))
{
filepath = dir + "\\" + dirp->d_name;
// If the file is a directory (or is in some way invalid) we'll skip it
if (stat( filepath.c_str(), &filestat )) continue;
if (S_ISDIR( filestat.st_mode )) continue;
// procesar tildes
string letter;
bool mod = false; // filename modified?
unsigned int i = 0; // count
while( i < 256 && dirp->d_name[ i ] != 0 )
{
letter = dirp->d_name[i];
if ( dictionary.find( letter[ 0 ] ) != dictionary.end() )
{
dirp->d_name[ i ] = dictionary[ letter[ 0 ] ][ 0 ];
mod = true;
}
i++;
}
if ( mod )
{
string oldname = filepath;
string newname = dir + "\\" + string( dirp->d_name );
rename ( oldname.c_str(), newname.c_str() );
cout << "RENOMBRADO : " << oldname << " A " << newname << endl;
oldname = newdir + "\\" + string(dirp->d_name);
CopyFile( newname.c_str(), oldname.c_str(), false);
cout << "COPIADO: " << newname << " A " << oldname << endl << endl;
}
}
closedir( dp );
return 0;
}