This forum is in archive mode. You will not be able to post new content.

Author Topic: Help making a tool  (Read 944 times)

0 Members and 1 Guest are viewing this topic.

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Help making a tool
« on: February 20, 2012, 08:39:38 PM »
xChat ruined my life putting \r in the filename on Ubuntu, so I need to rename every log file without that \r or I can't copy to NTFS.
I tried to do it in Python but I ran into a major problem.

Listing files in the folder is fine and I get the whole name. But when I need to rename it, it somehow omits everything before the \r (including it), so the filename is invalid and Python assumes that file does not exist.

Would be nice if someone knew a workaround or would make a script for me.

Here's a sample output:
Printing the name as it gets detected:
Code: [Select]
['EvilZone\r-#animalsex.txt']
But when I copy that filename to NP++, it shows as \r\n. Either way it does not find a correct file.

Printing the name from a list:
Code: [Select]
-#animalsex.txt
So what I want to do in a nutshell is to take a file, get its filename that contains \r or \r\n, remove that/those symbols and rename the file with the same name without that/those symbols.

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: Help making a tool
« Reply #1 on: February 20, 2012, 09:10:13 PM »
Nevermind. Forgot that on Linux I can use this command:
Code: [Select]
rename -v -f 's/\r//' xchatlogs/*.txt
Thanks to Satori for reminding me :D

Offline imation

  • Peasant
  • *
  • Posts: 141
  • Cookies: 2
    • View Profile
Re: Help making a tool
« Reply #2 on: February 20, 2012, 09:19:58 PM »
ah lol beat me too it

"RENAME"

http://linux.die.net/man/1/rename

 



Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.