Jump to content
  • 0
Sign in to follow this  
Cunoo

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

Question

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

Share this post


Link to post

7 answers to this question

Recommended Posts

  • 0

Other way for windows 

import os

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

 

Share this post


Link to post
  • 0
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.

Share this post


Link to post
  • 0
  • 0
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)

 

Share this post


Link to post
  • 0

Well, instead of removing them u can access them and just remove the content

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • 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.