Jump to content

[PYTHON] os.remove() does not working.


Recommended Posts

Hi guys,

I want create "new" protection for client check files, but I have one little problem..

90% of code working good, problem is os.remove() does not delete files in folder..

Here is my modified code:

 

def BGMcheckFile():
	BGM = os.listdir("BGM")

	Index = ["a_rhapsody_of_war.mp3", "back_to_back.mp3", "catacomb_of_devil.mp3", "death_of_landmark.mp3", "desert.mp3", "enter_the_east.mp3", "follow_war_god.mp3", "characterselect.mp3", "last-war2.mp3", "login_window.mp3", "lost_my_name.mp3", "m2bg.mp3", "monkey_temple.mp3", "mountain_of_death.mp3", "Only_my_battle.mp3", "open_the_gate.mp3", "save_me.mp3", "wedding.mp3", "wonderland.mp3", "xmas.mp3", "lastplay.inf"]

	if BGM != Index:
		for Data in BGM:
			if not Data in Index:
				try:
					os.remove(Data)
				except:
						app.Abort()

	if Index != BGM:
		for Data in Index:
			if not Data in BGM:
				app.Abort()
			else:
				pass
BGMcheckFile()

Someone know, where is problem? I tried use "os.chmod" for permission but same problem.

Thanks for useful help

Link to comment
Share on other sites

16 hours ago, ManiacRobert said:

os was disabled on windows 10.

I use win 7.  This is not my problem, but thank you.
 

15 hours ago, tierrilopes said:

You can do that easilly on the binary.

How? Please tell me if you have idea.
 

15 hours ago, Kori said:

Other way for windows 


import os

os.system('del /F fileName.txt')

 

Thank you, but I need delete unexpected files in folders without my "index" if you know what I mean.

Link to comment
Share on other sites

  • Premium
3 hours ago, Cunoo said:

I use win 7.  This is not my problem, but thank you.
 

How? Please tell me if you have idea.
 

Thank you, but I need delete unexpected files in folders without my "index" if you know what I mean.

import os
files = [i for i in os.listdir() if i not in ('new_models', 'creat_model.py', 'my_mos.tit')]
subprocess.call(['rm','-r'] + files)

Or

import glob
files = [i for i in glob.glob("*") if i not in ('new_models', 'creat_model.py', 'my_mos.tit')]
subprocess.call(['rm','-r'] + files)

 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.