Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Quick python script to change all file names of an extension

import os
import random

os.getcwd()


extension = input("What's the extension of the file names you want to change ? \nexample : .mp4 or .jpg \n")
for f in os.listdir():
fname , fext = os.path.splitext(f)
if fext==extension:
fname = str(random.randint(1,100000000))
newname= "{}{}".format(fname,fext)
os.rename(f,newname)

just learning guys 😁
Use "php" or "code" tags to preserve indentation when posting code.
PHP Code

<?php 
import os
import random

os
.getcwd()

extension = input("What's the extension of the file names you want to change ? \nexample : .mp4 or .jpg \n")
for 
f in os.listdir():
    
fname , fext = os.path.splitext(f)
    if 
fext==extension:
        
fname = str(random.randint(1,100000000))
        
newname= "{}{}".format(fname,fext)
        
os.rename(f,newname) 
Yea, actually forgot them but learned them from you in the first place , thanks
Because sod readability
PHP Code

<?php 
#!/urs/bin/python3
import os
import random

extension 
= input("What's the extension of the file names you want to change ? \nexample : .mp4 or .jpg \n")
[
os.rename(f,str(random.randint(1,10**6))+os.path.splitext(f)[1]) for f in os.listdir() if os.path.splitext(f)[1] == extension] 
¸„»°'´¸„»°'´Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est ¸„»°'´`'°«„¸`'°«„¸¸„»°'´
You guys know he's trying to create some form of ransomware, right?
Skype messages are NOT valid evidence, and here's why.
(Aug 25, 2017 06:45 AM)Ensky Wrote:  You guys know he's trying to create some form of ransomware, right?

I heard renaming files or removing their extension is a good ransomware.

Either way the script would be open for anyone to see.
¸„»°'´¸„»°'´Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est ¸„»°'´`'°«„¸`'°«„¸¸„»°'´
(Aug 25, 2017 06:45 AM)Ensky Wrote:  You guys know he's trying to create some form of ransomware, right?

Wuuuuut ? I'm a beginner man , didn't even think of it , but now that you say it 😈 😈 😁
(Aug 25, 2017 06:04 AM)vorticalbox Wrote:  Because sod readability
PHP Code

<?php 
#!/urs/bin/python3
import os
import random

extension 
= input("What's the extension of the file names you want to change ? \nexample : .mp4 or .jpg \n")
[
os.rename(f,str(random.randint(1,10**6))+os.path.splitext(f)[1]) for f in os.listdir() if os.path.splitext(f)[1] == extension] 

This isn't good practice. The beauty of Python is in its readability, one liners are nice and all, but this isn't a good way to do things.
(Aug 26, 2017 03:42 AM)emento Wrote:  This isn't good practice. The beauty of Python is in its readability, one liners are nice and all, but this isn't a good way to do things.

I know I just let trying to one liner things
¸„»°'´¸„»°'´Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est ¸„»°'´`'°«„¸`'°«„¸¸„»°'´
(Aug 25, 2017 06:04 AM)vorticalbox Wrote:  Because sod readability
PHP Code

<?php 
#!/urs/bin/python3
import os
import random

extension 
= input("What's the extension of the file names you want to change ? \nexample : .mp4 or .jpg \n")
[
os.rename(f,str(random.randint(1,10**6))+os.path.splitext(f)[1]) for f in os.listdir() if os.path.splitext(f)[1] == extension] 

I just had involuntary nervous twitches.
[Image: TEGE4Zx.png]
Puzzle level: 2/5
(Aug 26, 2017 05:08 AM)nOrr Wrote:  I just had involuntary nervous twitches.

Next time I'll add a trigger warning :P
¸„»°'´¸„»°'´Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est ¸„»°'´`'°«„¸`'°«„¸¸„»°'´
(Aug 26, 2017 05:51 AM)vorticalbox Wrote:  Next time I'll add a trigger warning :P

🤝

[warn]
[Image: TEGE4Zx.png]
Puzzle level: 2/5
@Lukos123:

If you are interested in renaming files to random strings instead of numbers, you may use module 'strgen'


To generate 12 letter random string:

Code
import strgen
strgen.StringGenerator('[\1]{12}').render()
Nice Code man.

PHP Code

<?php 
import os
Kys 
= input("What do you want to do? : ")
if 
Kys == 'kys':
       
os.system('KYS!')
      print(
'No such command but you killed yourself anyway') 
Malware Collection:
  • FKeylogger - Written in Python. (PM for Details)
  • Ded Kills PC Permanently. Also written in Python. (PM for Details)
(Aug 27, 2017 11:56 AM)zer0dev Wrote:  @Lukos123:

If you are interested in renaming files to random strings instead of numbers, you may use module 'strgen'


To generate 12 letter random string:

Code
import strgen
strgen.StringGenerator('[\1]{12}').render()

thanks a lot 🤝


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by Bass_ReevesAug 20, 2023 01:44 AM 9 630 Aug 20, 2023 01:44 AM
Last Post: Lucky4L
[.NET] by MarwenSep 24, 2022 04:19 PM 10 637 Sep 24, 2022 04:19 PM
Last Post: BinaryFox
[Shell] by 1Artemis1Nov 7, 2020 05:24 PM 2 160 Nov 7, 2020 05:24 PM
Last Post: 1Artemis1