Quantcast

Maximum PC

It is currently Wed Apr 23, 2014 11:43 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: VB.NET file handling help
PostPosted: Fri Nov 12, 2004 11:20 am 
8086
8086

Joined: Fri Jul 09, 2004 10:41 pm
Posts: 14
Hi all,

I was wondering if anyone here has some experience working with files in VB.Net...

Basically what I would like to do is create a simple program that will take input from a textbox containing a directory on the HDD (later I'll change this to a folder browser, but for simplicity, i just want to start out with a simple tb) and then search for a particular string within that directory (and it's subdirectories, if any).
If any filenames containing the string are found, I'd like to dump the list into a listbox. THEN, I'm going to have a button that will allow you to REPLACE the string that was searched for with another string (thereby recursing thru the files and RENAMING them)...

Thats what the program should do, and I have a decent framework set up, but I was wondering if anyone knows how to rename a file thru VB.Net.

Thanks! :D

Nouveaux21


Top
  Profile  
 
 Post subject:
PostPosted: Fri Nov 12, 2004 5:46 pm 
Team Member Top 100
Team Member Top 100

Joined: Fri Sep 17, 2004 5:35 pm
Posts: 1176
Here's how I'd do it:

Get the input directory and string. Now, set up a findfilesindirectory function that returns an array of the files in the directory. If you find another directory, then you can call the findfilesindirectory with the subdirectory as the dir to search.
That takes care of the files in the directory and its subdirectories.

Now, with each list, look at each filename and see if it has the string in it. If it does, then add that to a separate list (with directory info).

Now, display the 2nd list of files in your listbox. Now you can rename each file with the MoveFile function.


Top
  Profile  
 
 Post subject:
PostPosted: Sat Nov 13, 2004 5:46 pm 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000

Joined: Mon Jun 14, 2004 2:50 pm
Posts: 45
Location: Rochester, NY
If you start out with a File Dialog window, you can save yourself some time in the long run.

Code:
/// This is C#, not VB.  It shouldn't be hard to convert between
/// the two.
OpenFileDialog ofd = new OpenFileDialog();

/// Your event method..
protected void file_click( object sender, EventArgs ea ) {
    /// If the dialog box opens up..
    if( ofd.ShowDialog() == DialogResult.OK ) {
        string[] files = ofd.FileNames
        /// rename your files..
    }
}


That doesn't exactly do you what you described. I'm guessing you have a 'Rename' button in which case it's click event would open the file dialog and either prompt for the rename string or take the string from a textbox prior to clicking the button. In any event, if you start with the OpenFileDialog object, some of the busy work is done for you.


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group