|
i am developing a small appdesigned tomake it a little convinient to modify the file name of eachimage in acertain directory in batch.and i have managed to display the images in the DataGridView control.so,how should i modify the file name of each image in one submit operation?could somebody give me someadviceor tips?thank you so much!!! | | wilbyang Friday, August 21, 2009 6:00 PM | hi wilbyang, lets say you have one column which display name of images, and that is editable and user rename it, and there is button OK, so on OK click you write your code. Loop through all rows and by using System.IO.File.Move(sourcefileName, destFileName) you can rename all images.
- Marked As Answer byKira QianMSFT, ModeratorFriday, August 28, 2009 8:43 AM
-
| | NareshG Friday, August 21, 2009 7:13 PM | Hi wilbyang, I have made a sample for you which can rename all jpg files in a folder to MyPic[X ].jpg "X " will be increase by 1 for each file. public void RenameAllFile(string folderPath) { DirectoryInfo dirInfo = new DirectoryInfo(folderPath); FileInfo[] fileInfo = dirInfo.GetFiles("*.jpg"); for (int i = 0; i < fileInfo.Length; i++) { fileInfo[i].MoveTo(folderPath + "\\MyPic" + i.ToString() + ".jpg"); } } .NET doesn't offer Rename method. So I have to use MoveTo method. Once the destination folder is the same as the source folder. The file will be renamed. I think this will help you to solve the problem. If you have anything unclear, please feel free to tell me. Sincerely, Kira Qian Please mark the replies as answers if they help and unmark if they don't.- Marked As Answer byKira QianMSFT, ModeratorFriday, August 28, 2009 8:43 AM
-
| | Kira Qian Monday, August 24, 2009 9:48 AM | hi wilbyang, lets say you have one column which display name of images, and that is editable and user rename it, and there is button OK, so on OK click you write your code. Loop through all rows and by using System.IO.File.Move(sourcefileName, destFileName) you can rename all images.
- Marked As Answer byKira QianMSFT, ModeratorFriday, August 28, 2009 8:43 AM
-
| | NareshG Friday, August 21, 2009 7:13 PM | as i am a novice to windows app development,would you please give me some fake codes to describe it more clearly? thank you so much!!! | | wilbyang Friday, August 21, 2009 11:34 PM | Hi wilbyang, I have made a sample for you which can rename all jpg files in a folder to MyPic[X ].jpg "X " will be increase by 1 for each file. public void RenameAllFile(string folderPath) { DirectoryInfo dirInfo = new DirectoryInfo(folderPath); FileInfo[] fileInfo = dirInfo.GetFiles("*.jpg"); for (int i = 0; i < fileInfo.Length; i++) { fileInfo[i].MoveTo(folderPath + "\\MyPic" + i.ToString() + ".jpg"); } } .NET doesn't offer Rename method. So I have to use MoveTo method. Once the destination folder is the same as the source folder. The file will be renamed. I think this will help you to solve the problem. If you have anything unclear, please feel free to tell me. Sincerely, Kira Qian Please mark the replies as answers if they help and unmark if they don't.- Marked As Answer byKira QianMSFT, ModeratorFriday, August 28, 2009 8:43 AM
-
| | Kira Qian Monday, August 24, 2009 9:48 AM |
|