1 Replies - 111 Views - Last Post: 06 November 2019 - 06:41 AM Rate Topic: -----

#1 Tudarris94   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-June 18

Copy and rename multiple files

Posted 05 November 2019 - 05:37 AM

View Postzakary, on 26 June 2008 - 12:31 PM, said:

// where you have "*.*" and the correct way is "*"
string[] files = System.IO.Directory.GetFiles(@"C:\Development\HumanHunter", "*");
                        
            foreach (string file in files)
            {
                // here we set the destination string with the file name
                string destfile = @"C:\test\destination\" +  System.IO.Path.GetFileName(file); 
                // now we copy the file to that destination
                System.IO.File.Copy(file, destfile, true);
            }
[/   private void Rename_btn_Click(object sender, EventArgs e)
        {
            path = Application.StartupPath.Substring(0, Application.StartupPath.LastIndexOf("bin"));
            subFoda = path + "\\Trimmed Results\\";
           // Directory.CreateDirectory(subFoda); 
                DirectoryInfo d = new DirectoryInfo(subFoda);
                FileInfo[] infos = d.GetFiles();
                foreach (FileInfo f in infos)
                {
                    File.Move(f.FullName, f.FullName.Replace("test ", ""));//i want the app suold pick the names and replaces other array of names
                }
            MessageBox.Show("files successfully renamed!!");
             
        }


Good Day, zakari; my case is bit different, i want to rename those individual files to other names e.g 'sdaxcvf2dr4g.pdf',hdasdas223hh.pdf... to firstFile.pdf, 2ndFileName.pdf respectively. i dont seem to be getting it.any help will be appreciated!

This post has been edited by Skydiver: 06 November 2019 - 06:36 AM
Reason for edit:: Fixed mangled tags.


Is This A Good Question/Topic? 0
  • +

Replies To: Copy and rename multiple files

#2 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7132
  • View blog
  • Posts: 24,225
  • Joined: 05-May 12

Re: Copy and rename multiple files

Posted 06 November 2019 - 06:41 AM

Welcome to DIC! In the future please do not revive old threads, specially if the OP for the thread has not logged in for years. Instead create a new thread and either quote the relevant items, or link back to the old thread. I've started a new topic for you here.

Can you show us what current code you have for attempting to do this? This is a pretty straightforward task where the only complicated part will be determining the names of the files if are really going to use "firstFile", "2ndFileName", "3rdFileName", "4thFileName", etc as the resulting file names. I highly recommend choosing a different number scheme that is more localizable unless your target audience are English speakers only.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1