Ich verwende das folgende Skript, um ein Kopierrecht für alle Dateien in den Verzeichnissen und Unterverzeichnissen für ein bestimmtes Verzeichnis hinzuzufügen, das als erstes Argument übergeben wurde. Ich führe das Skript wie folgt aus, aber es tritt der folgende Fehler auf ...
Kann jemand Eingaben zu ohw machen, um das Problem zu beheben?
C:\Dropbox\copyrights>python Add_copyright.py .
Traceback (most recent call last):
File "Add_copyright.py", line 69, in
prepend_file(fullname, dirpath)
File "Add_copyright.py", line 60, in prepend_file
os.rename(temp_fname, fullname)
WindowsError: [Error 183] Cannot create a file when that file already exists
import fnmatch
import os
import shutil
import sys
import tempfile
file_patterns_to_match = ['*.c','*.h','*.cpp','*.txt']
headertext = """/*
* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
*
* Previously licensed under the ISC license by Qualcomm Atheros, Inc.
*
*
* Permission to use, copy, modify, and/or distribute this software for
* any purpose with or without fee is hereby granted, provided that the
* above copyright notice and this permission notice appear in all
* copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
"""
# make any newlines in headertext match the system line ending
headertext = headertext.replace('\n', os.linesep)
def want_this_file(fname):
for pat in file_patterns_to_match:
if fnmatch.fnmatch(fname, pat):
return True
return False
def prepend_file(fullname, path):
# with statement means temp file is written and closed at end of with
with tempfile.NamedTemporaryFile(dir=path, delete=False) as out_file:
# get the name immediately
temp_fname = out_file.name
try:
# use binary mode to avoid newline translations
with open(fullname, "rb") as in_file:
out_file.write(headertext)
shutil.copyfileobj(in_file, out_file)
except Exception:
# on any error, clean up temp file and re-raise exception
try:
os.remove(temp_fname)
except Exception:
print("unable to clean up temp file: " + temp_fname)
pass
raise
# rename temp file to fullname, clobbering original
os.rename(temp_fname, fullname)
start_directory = sys.argv[1]
for dirpath, dirnames, filenames in os.walk(start_directory):
for fname in filenames:
if want_this_file(fname):
fullname = os.path.join(dirpath, fname)
prepend_file(fullname, dirpath)
Ich verwende das folgende Skript, um ein Kopierrecht für alle Dateien in den Verzeichnissen und Unterverzeichnissen für ein bestimmtes Verzeichnis hinzuzufügen, das als erstes Argument [url=viewtopic.php?t=23808]übergeben[/url] wurde. Ich führe das Skript wie folgt aus, aber es tritt der folgende Fehler auf ... Kann jemand Eingaben zu ohw machen, um das Problem zu beheben?
FEHLER:-
[code]C:\Dropbox\copyrights>python Add_copyright.py . Traceback (most recent call last): File "Add_copyright.py", line 69, in prepend_file(fullname, dirpath) File "Add_copyright.py", line 60, in prepend_file os.rename(temp_fname, fullname) WindowsError: [Error 183] Cannot create a file when that file already exists [/code]
CODE:-
[code]import fnmatch import os import shutil import sys import tempfile
headertext = """/* * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. * * Previously licensed under the ISC license by Qualcomm Atheros, Inc. * * * Permission to use, copy, modify, and/or distribute this software for * any purpose with or without fee is hereby granted, provided that the * above copyright notice and this permission notice appear in all * copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ """
# make any newlines in headertext match the system line ending headertext = headertext.replace('\n', os.linesep)
def want_this_file(fname): for pat in file_patterns_to_match: if fnmatch.fnmatch(fname, pat): return True return False
def prepend_file(fullname, path): # with statement means temp file is written and closed at end of with with tempfile.NamedTemporaryFile(dir=path, delete=False) as out_file: # get the name immediately temp_fname = out_file.name
try: # use binary mode to avoid newline translations with open(fullname, "rb") as in_file: out_file.write(headertext) shutil.copyfileobj(in_file, out_file) except Exception: # on any error, clean up temp file and re-raise exception try: os.remove(temp_fname) except Exception: print("unable to clean up temp file: " + temp_fname) pass raise # rename temp file to fullname, clobbering original os.rename(temp_fname, fullname)
start_directory = sys.argv[1]
for dirpath, dirnames, filenames in os.walk(start_directory): for fname in filenames: if want_this_file(fname): fullname = os.path.join(dirpath, fname) prepend_file(fullname, dirpath) [/code]
Ich wollte gerade eine Godot -Erweiterung bauen, die ich in C ++ gemacht habe. Mit dem Aufbau der Godot-CPP-Bibliothek lief es gut, aber ich habe einen Fehler bekommen, als ich versuchte, das Plugin...
Ich wollte gerade eine Godot -Erweiterung bauen, die ich in C ++ gemacht habe. Mit dem Aufbau der Godot-CPP-Bibliothek lief es gut, aber ich habe einen Fehler bekommen, als ich versuchte, das Plugin...
Heute habe ich ein Pop-up, in dem Spyder auf 6.0.1 aktualisiert werden kann. Wenn ich versuche, es zu aktualisieren, erhalte ich die folgende Fehlermeldung:
Ich versuche, mehrere digitale Signaturen mit Apache PDFBox 3.0.5 auf eine einzelne PDF -Datei anzuwenden, aber ich stehe in ein Problem, bei dem die zuvor gültige Signatur überschrieben oder...
Ich habe ein jQuery 1.5+-Skript und Sie wählen eine Menge in einem Dropdown-Menü aus (1,2,3 usw.) und es multipliziert diese Menge mit 1,50 $, um Ihnen einen Gesamtpreis anzuzeigen. Im Grunde geht es...