私はpython 2.7xで作業しています。私はPythonにはかなり新しく、本当にあなたの助けに感謝します。私はこのエラーについていくつかの名前を挙げるために以下を含む多くの記事を読んでいます:txtファイルの名前を変更します。編集されたバージョン:[エラー183]ファイルが既に存在する場合、ファイルを作成できません。
WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'new.dat' - >私のファイルの終了指示はすでに終わりです。
python 2 [Error 32] The process cannot access the file because it is being used by another process私は使用しているpythonプログラムに何らかのエラーがあり、コンピュータが管理上保護されているためパスウェイを編集できないので、私はシャットルを使用できません。
Rename Files in Python - 提案に従った後、私はNameErrorを得た>:名前は '名前の変更' が...代わりに定義されていません。私のコードを修正しようとした後/
などなど
、私は」それでも同じエラーが出ます。私がやりたい何
は次のとおりです(。firstfound.txtするすなわちfirst.txt)私は、ファイルのいずれかが特定の文字列が含まれている場合、私はテキストファイル の名前を変更するだろう、ディレクトリ内のファイルを読み込む
編集されたバージョン: 私は(abc.closeを移動しようとした)私は、ファイル名前を変更する前に:
import os
fname = raw_input("Enter file name: ")
#fill in file directory here
abc = open(fname)
for line in abc:
if not line.find("scramble") :
continue
oldfile = fname
abc.close()
if oldfile == fname:
for title in fname:
endname = title.find('.txt')
oldtitle = title[:endname]
newfile = oldtitle +"found.txt"
os.rename(oldfile,newfile)
をしかし、私は、最後の行の代わりに、このエラーが発生しています。 os.rename(oldfile、newfile) WindowsError:[エラー183]ファイルが既に存在する場合、ファイルを作成できません。私のフォルダには新しい名前のファイルはありません。 アドバイスをいただきありがとうございます!
編集版2:私はこの他のコードを試しましたが、WindowsError:[Error 5]アクセスが拒否されました。私は管理者権限がないので、txtファイルの名前を変更できないことがあるかどうか分かりますか?ありがとうございました!
import os
fname = raw_input("Enter file name: ")
#fill in file directory here
abc = open(fname)
for line in abc:
if not line.find("scramble") :
continue
oldfile = fname
abc.close()
if (oldfile == fname): #+'/' + "a.txt"
for title in fname:
endname = title.find('.txt')
oldtitle = title[:endname]
new_file = oldtitle +'/' + "a.txt"
os.rename(fname,new_file)
イニシャルバージョン:私が得たエラーは、os.rename行です。 「WindowsError:[エラー32]それは別のプロセスによって使用されているため、プロセスはファイルにアクセスできません」以下に示すように
私の全体のプログラムコードは次のとおりです。
import os
fname = raw_input("Enter file name: ")
#fill in file directory here
abc = open(fname)
for line in abc:
if not line.find("scramble") :
continue
old_file = fname
for title in fname:
endname = title.find('.txt')
oldtitle = title[:endname]
new_file = oldtitle +'/' + "found.txt"
os.rename(old_file,new_file) ##WindowsError: [Error 32] The process cannot access the file because it is being used by another process
abc.close()
私はなぜこのエラーを理解していません持続する。 (私はすべてのファイルを閉じた&フォルダ)。どうもありがとうございました!
これは、このプロセスか他のプロセスがファイルにアクセスしていることです。 –
私はabcを入れようとしました。close()の前に "for title in fname:"が表示されますが、代わりにエラーが表示されます: "" for abc: ValueError:閉じたファイルのI/O操作 " – Sandy
他のプロセスは何でしょうか? @PrajjwalSrivastav – Sandy