EDN Admin
Well-known member
using System;<br/>
using System.Collections.Generic;<br/>
using System.Linq;<br/>
using System.Text;<br/>
using System.IO;
namespace Format_Files<br/>
{<br/>
class Program<br/>
{<br/>
static void Main(string[] args)<br/>
{<br/>
string s;<br/>
StreamWriter sw;<br/>
string sf;<br/>
string[] images;<br/>
int x;<br/>
int y;<br/>
sw = new StreamWriter(@"d:stream.txt");<br/>
sf = @"d:RadarImagesDownloaded";<br/>
images = Directory.GetFiles(sf, "*.jpg");<br/>
<br/>
Console.WriteLine("--- Files: ---");
<br/>
for (x = 0; x < images.Length; x++)<br/>
{<br/>
<br/>
<br/>
s = images[x];<br/>
int i = s.IndexOf("radar");<br/>
int t = s.IndexOf(".jpg");<br/>
string d = s.Substring(i+5,s.Length-t - 1);<br/>
int numbers = Convert.ToInt32(d);<br/>
string c = sf + @"radar" + numbers.ToString("D6") + ".jpg";
<br/>
Console.WriteLine("index: "+x+" filename:"+images[x]);
sw.WriteLine("index: "+x+" Substring:"+ d + " Converted numbers: " + numbers + " New fileNames: " + c);<br/>
if ((x % 500) == 0) // just to help us see the printing on the screen.. cause it is too fast..so
<br/>
// "pausing" every 500 .. (wait for user press )<br/>
{<br/>
Console.WriteLine(" just pausing so user can see.. : press any key to continue ...");<br/>
Console.ReadKey(false);<br/>
}<br/>
}<br/>
sw.Close();<br/>
}<br/>
}<br/>
}
Now the strin c contain all the files in the new format i want to create this files and rename the old files wich are string s.
Si tried to add after the string c:
File.Move(c,s); But im getting error say the files in C dosent exist in the directory. So i need first to create the files then rneame ? I want to rename or better to replace the new files in C with the ones in S. And then i want to delete
all the files in S!!
Thanks.
<hr class="sig danieli
View the full article
using System.Collections.Generic;<br/>
using System.Linq;<br/>
using System.Text;<br/>
using System.IO;
namespace Format_Files<br/>
{<br/>
class Program<br/>
{<br/>
static void Main(string[] args)<br/>
{<br/>
string s;<br/>
StreamWriter sw;<br/>
string sf;<br/>
string[] images;<br/>
int x;<br/>
int y;<br/>
sw = new StreamWriter(@"d:stream.txt");<br/>
sf = @"d:RadarImagesDownloaded";<br/>
images = Directory.GetFiles(sf, "*.jpg");<br/>
<br/>
Console.WriteLine("--- Files: ---");
<br/>
for (x = 0; x < images.Length; x++)<br/>
{<br/>
<br/>
<br/>
s = images[x];<br/>
int i = s.IndexOf("radar");<br/>
int t = s.IndexOf(".jpg");<br/>
string d = s.Substring(i+5,s.Length-t - 1);<br/>
int numbers = Convert.ToInt32(d);<br/>
string c = sf + @"radar" + numbers.ToString("D6") + ".jpg";
<br/>
Console.WriteLine("index: "+x+" filename:"+images[x]);
sw.WriteLine("index: "+x+" Substring:"+ d + " Converted numbers: " + numbers + " New fileNames: " + c);<br/>
if ((x % 500) == 0) // just to help us see the printing on the screen.. cause it is too fast..so
<br/>
// "pausing" every 500 .. (wait for user press )<br/>
{<br/>
Console.WriteLine(" just pausing so user can see.. : press any key to continue ...");<br/>
Console.ReadKey(false);<br/>
}<br/>
}<br/>
sw.Close();<br/>
}<br/>
}<br/>
}
Now the strin c contain all the files in the new format i want to create this files and rename the old files wich are string s.
Si tried to add after the string c:
File.Move(c,s); But im getting error say the files in C dosent exist in the directory. So i need first to create the files then rneame ? I want to rename or better to replace the new files in C with the ones in S. And then i want to delete
all the files in S!!
Thanks.
<hr class="sig danieli
View the full article