C# – Copying a file with the same name without overwriting
by edy_3dz on May.29, 2011, under Code snippets
I recently encountered a situation where I needed to copy some files over a location where files with the same name already existed, and overwriting them wasn’t an option. So, the following code snippet verifies if a file with the same name already exists, in case which it tries to put a number after the file’s name.
if (File.Exists(path + fileName)
{
int count = 1;
string[] fileNameSplit = fileName.Split(new char[] { '.' });
string ext = "." + fileNameSplit[fileNameSplit.Length - 1];
string prefix = fileName.Substring(0, fileName.Length - ext.Length);
while (File.Exists(path + fileName))
{
fileName = prefix + "(" + count.ToString() + ")" + ext;
count++;
}
File.Copy(source, path + fileName);
}
else
{
File.Copy(source, path + fileName);
}
I hope that you’ll find this helpful
How to import books to Aldiko
by edy_3dz on Feb.09, 2011, under Android
If you want to import your own ebooks to Aldiko, one of the best ebook readers on Android, this is what you have to do:
- Install some ebook management software on your PC, for example Calibre
- Import your ebooks and convert them to epub format
- Copy the epub files to your Android smartphone to phone_directory/ebooks/import ; if the folder doesn’t exists, create it
- Start Aldiko, press the menu key, select Import, and wait until the files are copied
Enjoy!
How to change GRUB default entry
by edy_3dz on Jan.31, 2011, under Linux
If you installed Linux over Windows, the bootloader will change to GNU GRUB, and it’s default entry will be the fresh installed Linux. If you don’t want that, and you want Windows to be the default entry, this is what you have to do:
- in GRUB, count which line is the entry which you want to make it default; the count starts from 0, so the second line is 1, the third is 2 etc.
- boot into Linux
- open Terminal
- run the following command: sudo gedit /boot/grub/grub.cfg
- if prompted, enter your password
- in gedit, find the following line: set default=”0″
- change “0″ to the line you want
- save the file, and exit.
- you’re done
If you don’t want to use GRUB at all, you can try EasyBCD (runs only on Windows), it’s a very good boot manager.
Changing Yahoo Messenger’s status using C#
by edy_3dz on Aug.31, 2010, under Code snippets
Some people asked me how I change Yahoo Messenger’s status in my application called Emoticon Status Generator. So I’ll make public the code snippet that I used to accomplish this.
[DllImport("USER32.DLL", EntryPoint="FindWindowA",
CallingConvention=CallingConvention.StdCall)]
private static extern IntPtr FindWindow(string sClassName,
string sWindowName);
[DllImport("USER32.DLL", EntryPoint="PostMessageA",
CallingConvention=CallingConvention.StdCall)]
private static extern bool PostMessage(IntPtr hWnd, uint iMsg,
long wParam, long lParam);
void ChangeYahooStatus (string newStatus)
{
// Get the current signed in user
RegistryKey keyYahooPager =
Registry.CurrentUser.OpenSubKey("Software\\Yahoo\\Pager");
string userName = (string)keyYahooPager.GetValue ("Yahoo! User ID");
keyYahooPager.Close();
// Now open the current user's profile and set the new status message
// We have to pass true to OpenSubKey to request write access
RegistryKey keyYahooCustomMessages =
Registry.CurrentUser.OpenSubKey ("Software\\Yahoo\\Pager\\profiles\\"
+ userName + "\\Custom Msgs", true);
// Set the 5th message, seems like yahoo messenger has the
//functionality to move the newly set message up as the first one.
keyYahooCustomMessages.SetValue ("5_W", newStatus);
keyYahooCustomMessages.Close ();
// We are done setting the value in the registry. We now need to notify
// Yahoo Messenger of this change
// Find the Messenger window and send it the notification
// 0x111: WM_COMMAND
// 0x188: Code 392
IntPtr hWndY = FindWindow ("YahooBuddyMain", null);
PostMessage (hWndY, 0x111, 0x188, 0);
}
It should work with Yahoo Messenger 9 and 10, not tested with other versions.
I hope that you’ll find useful this code snippet in developing some nice piece of software.
Nokia Qt SDK Setup – Online installer error
by edy_3dz on Aug.17, 2010, under QT
I started learning QT, and today I wanted to install Nokia Qt SDK, so I could build applications for my Symbian device. But I faced a little problem: the online installer was giving me the folowing error, over and over again:
Error during installation process:
The installer was not able to get the old path from \NokiaQtSDK\Symbian\SDK\bin\qmake.exe.(maybe it is broken or removed) It tried to patch the Qt binaries, but all other files in Qt are unpatched.
This could result in a broken Qt version.
Retry/Ignore/Cancel
Afer spending some time searchig what is the cause of this error, reading on the QT bug tracker that it is due to bad internet conectivity (not in my case
), I saw that someone suggested that this error appears beacause of the antivirus. So I disabled my antivirus, tried again, and this time worked like a charm.
So if you are having trouble installing Nokia Qt SDK using the online installer, disabling your antivirus will do the trick
Was this article helpful? Leave a comment below!
