Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by AVividLight · Jan 25, 2012 at 10:33 PM · c#filessystem.iofolders

Add files to folder

Hey guys,

Sorry about the obscure title, but I have been trying to figure this out for so long, that I think my brain is melting... Anyway...

Basically, I want to take all the files in folder A and move them to C, which is inside B. Let me try to explain this a little better. I want to take all the files that are in the folder "tempPath", and move them to "folderA". This would be easy enough, but folderA already exists and it has stuff in it that I don't want to delete. And, for the life of me, I can't figure out how to do this!


tempPath is located at:

 static string tempPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + Path.DirectorySeparatorChar + "tempPath";

folderA is located at:

 static public string folderA = "/Users/" + Environment.UserName + "/Documents/HardFiles/folderA";


I really appreciate any help you can give me! ∆ Gibson

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by syclamoth · Jan 25, 2012 at 10:57 PM

Easy enough-

 using System.IO;

 // inside the function:
 foreach(string file in Directory.GetFiles(tempPath))
 {
     string fName = file.Substring(tempPath.Length + 1);
     File.Move(file, Path.Combine(folderA, fName));
 }

That should do it! Make sure that you don't have any files of the same name in the destination directory.

Comment
Add comment · Show 18 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image syclamoth · Jan 25, 2012 at 11:22 PM 1
Share

So, do you want it to overwrite those files? Or do you want it to skip them?

avatar image syclamoth · Jan 25, 2012 at 11:29 PM 1
Share

Yes, I get that, but the error you are reporting occurs when you are trying to move a file to a location where a file with the same name exists- what do you want to do in that situation?

avatar image syclamoth · Jan 25, 2012 at 11:51 PM 1
Share

Ok then. Have you tried a $$anonymous$$imal case? Just test it with two string literals and see if that works. I can't quite see what's going on here yet.

avatar image syclamoth · Jan 25, 2012 at 11:58 PM 1
Share

I'm not sure if that'd be useful... It's often difficult to read and comprehend long programs without having written them yourself. I can try, if you like.

avatar image AVividLight · Jan 26, 2012 at 12:00 AM 1
Share

I was just going to post the function, not the full code

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

File.Move wont work , error. IOException: Win32 IO returned ERROR_ALREADY_EXISTS. Path: 1 Answer

Distribute terrain in zones 3 Answers

Will System.IO.File work on Macs 2 Answers

How Do I Find Path of a File? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges