2016-12-18 11 views
1

スクリプトでは、C:/ Users/User/Desktop/FolderというファイルをzipファイルにしてZipFile.zip /の構造にzipファイルとして表示しますC:/ Users/user/Desktop/Folderだけでなく、ZipFile.zip/Folderの代わりに私はそれを修正する方法を見つけることができません。Pythonでファイルを詰めて移動する

私もバックアップ指定されたデバイスに作成されたzipファイルを移動しようとしている[お越しのコードは、行21-26である] [27行]

は私のコードは次のとおりです。

import os 
import sys 
import shutil 
import zipfile 
import traceback 

print ('Welcome to USB Backup Utility') 
print ('Created by: TheCryptek') 
print ('\nWhat directory would you like to back up?') 
print ('Example: C:/users/user/Desktop/Folder') 
backUp = raw_input('> ') # Files the user specified to back up 
print ('\nWhere would you like to back these files up at?') 
print ('Example USB Letter: E:/') 
backDevice = raw_input('> ') # Device the user specified to save the back up on. 
print ('\nName of the zip file you prefer?') 
print ('Example: Backup.zip') 
backZip = raw_input('> ') # The name of the zip file specified by the user 
print ('\nBackup started...') 
if not os.path.exists(backDevice + '/BackUp'): # If the BackUp folder doesn't exist on the device then 
    os.mkdir(backDevice + 'BackUp') # Make the backup folder on usb device 
backZip = zipfile.ZipFile(backZip, 'w') # Not sure what to say for lines 21 - 26 
for dirname, subdirs, files in os.walk(backUp): 
    backZip.write(dirname) 
    for filename in files: 
     backZip.write(os.path.join(dirname, filename)) 
    backZip.close() 
shutil.move(backZip, backDevice + '/BackUp') # Move the zip files created in working directory to the specified back up device -[ Something is wrong with this can't figure out what ]- 
print('Backup finished.') 
+0

コーディングヘルプを探しているようですが、あなたはあなたの質問を言い換えることができますので、それは[ガイドライン](http://stackoverflow.com/help/asking)に適合します。 –

+0

コーディングヘルプに関する何も表示されませんか、それとも私の質問の形式ですか? – TheCryptek

答えて

0

shutil.move()適切な送信元と送信先のパスを指定する必要があります。

あなたのプログラムでは、ソースパスとファイルオブジェクトは同じ名前です。そのオブジェクトを呼び出す代わりに、ファイルのパスを取る必要があります。

import os 
import sys 
import shutil 
import zipfile 
import traceback 

print ('Welcome to USB Backup Utility') 
print ('Created by: TheCryptek') 
print ('\nWhat directory would you like to back up?') 
print ('Example: C:/users/user/Desktop/Folder') 
backUp = raw_input('> ') # Files the user specified to back up 
print ('\nWhere would you like to back these files up at?') 
print ('Example USB Letter: E:/') 
backDevice = raw_input('> ') # Device the user specified to save the back up on. 
print ('\nName of the zip file you prefer?') 
print ('Example: Backup.zip') 
backZip = raw_input('> ') # The name of the zip file specified by the user 
print ('\nBackup started...') 

if not os.path.exists(backDevice + '/BackUp'): # If the BackUp folder doesn't exist on the device then 
    os.mkdir(backDevice + 'BackUp') # Make the backup folder on usb device 

bkZip = zipfile.ZipFile(backZip, 'w') # Not sure what to say for lines 21 - 26 
for dirname, subdirs, files in os.walk(backUp): 
    bkZip.write(dirname) 
    for filename in files: 
     bkZip.write(os.path.join(dirname, filename)) 
    bkZip.close() 

#print backZip,backDevice 
dest = backDevice + '/BackUp' 
#print dest 
shutil.move(backZip, dest) # Move the zip files created in working directory to the specified back up device -[ Something is wrong with this can't figure out what ]- 
print('Backup finished.') 
+0

提案された編集を行った後、私は今この[エラー](https://ghostbin.com/paste/2phpv)を取得します – TheCryptek

+0

@ TheCryptekは私のためにうまくいきます.. 1./home/shiva/abc 2 ./home/shiva/。 3 ab今度は/ home/shiva /にab.zipを作成し、/ home/shiva/Backupにab.zipを移動するか、サンプルパスを提供してください。 –

+0

backZip.blahをbkZip.blahに変更するのを忘れてしまった小さな入力ミスを修正しました。今は、指定されたパスにzipファイルが存在するかどうかを確認する必要があります。新しいジップを移動する:oありがとう! – TheCryptek

0

probの絶対パスを作成する必要があります。

+0

他のユーザーのコンピュータにある場合はどうすれば絶対パスにするのですか?使用するパスがわからないのですか? – TheCryptek

+0

あなたはGUIシステムを使用していないと考えています(私はあなたのことではないと思います)。通常は "ブラウズ"のことをやっていますが、この場合はGUIを持っていないということはありません。 –

関連する問題