简体   繁体   中英

C# Renaming a lot of files using formatted strings based on calculations

I am new around and learning C# programming.

I am working on modding the game Train Simulator and one of the tasks I've got into is renaming files and their contents for the routes used in the game. All the files used having codes that tells the game what objects should be placed where etc.

The first step that I am asking here is to rename the files themselves. The files are arranged like a coordinate-system, like this: List of files name +000000+000000.bin and counting. As you can see, the files are úsing a 6-digit numbers and starts with a + or - in the beginning like an XY-grid, relative to a point. My goal here is to mathematically increase or decrease the numbers in the XY-grid and make sure all the files are renamed according to the input provided by the user.

EDIT: The user would be moving point 0 somewehere else. if the file +000000+000000.bin should be renamed +000025-000067 then file +000000+000001.bin should be renamed +000025-000066.bin, -000003-000006-bin should be +000022-000070.bin and so on, by adding 25 in the first half and removing -67 from the other half of the filename

If there is someone out there who have a good suggestion about how to do this, then I would greatly appreciate this. English isn't my first language and C# is pretty new to me.

It is generally recommended to make a honest effort to try to find a solution before posting a question. If you have not already, you might want to read "how to ask a good question"

Some pointers to get you started:

  1. List all the files. See the GetFiles method.
  2. Split the filename into the x and y coordinates. See Substring
  3. Parse the x and y coordinates. See Parse
  4. Apply offset to x and y coordinates, I hope you will manage this.
  5. Format the new filename, See String.Format , format strings and Include sign
  6. Finally, Rename the file

This should give enough information to start to make a solution. If you run into specific issues it might be a good idea to post a more specific question of whatever you have an issue with.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM