473,672 Members | 2,511 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error message if there is a space in the source directory

I am trying to learn Python. I am working on a simple backup program
(code listed below). When using a source directory (the files to be
backed up) without spaces in the title, my program works fine [see
line 5]. If I try to access a directory with a space in the name the
program fails with this error message:

zip error:Nothing to do! (try: zip -qr C:\Backup\
\06.02.2007\Bac kUp@_10.03.57.z ip . -i C:\test\test2\\ )
Backup FAILED

I've been trying to find the answer for a while now but am stumped and
don't know exactly what to look for. Any help would be greatly
appreciated!
1. # C:\python25\pro grams\
2. # File name: backup3debug.py
3. import os, time
4. # 1. The files and directories to be backed up are specified in
a list.
5. source = [r'C:\test\test2 \\']
6. # 2. The backup must be stored in a main backup directory.
7. target_director y = r'C:\Backup\\'
8. # 3. The files are backed up into a zip file.
9. # 4. The name of the directory is the current date.
10. today = target_director y + time.strftime(' %m.%d.%Y')
11. # The current time is the name of the zip archive.
12. now = time.strftime(' BackUp@_%H.%M.% S')
13. # Create the subdirectory if it does not exist already.
14. if not os.path.exists( today):
15. os.mkdir(today)
16. print 'Successfully created directory', today
17. # The name of the zip file.
18. target = os.path.join(to day, now + '.zip')
19. # 5. We use the standard ''zip'' command to put the files in a
zip archive.
20. zip_command = "zip -qr %s %s" % (target, ' '.join(source))
21. print zip_command
22. # Run the backup
23. if os.system(zip_c ommand) == 0:
24. print 'sucessful backup to', target
25. else:
26. print 'Backup FAILED'

When using a source like this on line 5:

source = [r'C:\test\test 2\\']

which has a space in the title, the program will not work.
=============== =============== =============== =======
Windows XP sp2
Dell Latitude D600

Jun 2 '07 #1
3 2068
When using a source like this on line 5:
>
source = [r'C:\test\test 2\\']

which has a space in the title, the program will not work.
Try wrapping that argument in double quotes when you build the command

Jun 2 '07 #2
lu************* @gmail.com wrote:
I am trying to learn Python. I am working on a simple backup program
(code listed below). When using a source directory (the files to be
backed up) without spaces in the title, my program works fine [see
line 5]. If I try to access a directory with a space in the name the
program fails with this error message:

zip error:Nothing to do! (try: zip -qr C:\Backup\
\06.02.2007\Bac kUp@_10.03.57.z ip . -i C:\test\test2\\ )
Backup FAILED

I've been trying to find the answer for a while now but am stumped and
don't know exactly what to look for. Any help would be greatly
appreciated!
1. # C:\python25\pro grams\
2. # File name: backup3debug.py
3. import os, time
4. # 1. The files and directories to be backed up are specified in
a list.
5. source = [r'C:\test\test2 \\']
6. # 2. The backup must be stored in a main backup directory.
7. target_director y = r'C:\Backup\\'
8. # 3. The files are backed up into a zip file.
9. # 4. The name of the directory is the current date.
10. today = target_director y + time.strftime(' %m.%d.%Y')
11. # The current time is the name of the zip archive.
12. now = time.strftime(' BackUp@_%H.%M.% S')
13. # Create the subdirectory if it does not exist already.
14. if not os.path.exists( today):
15. os.mkdir(today)
16. print 'Successfully created directory', today
17. # The name of the zip file.
18. target = os.path.join(to day, now + '.zip')
19. # 5. We use the standard ''zip'' command to put the files in a
zip archive.
20. zip_command = "zip -qr %s %s" % (target, ' '.join(source))
21. print zip_command
22. # Run the backup
23. if os.system(zip_c ommand) == 0:
24. print 'sucessful backup to', target
25. else:
26. print 'Backup FAILED'
I realize that you have good intentions, but this script is commented to
death. Make a guess which points a reader may stumble over and only comment
these.
When using a source like this on line 5:

source = [r'C:\test\test 2\\']

which has a space in the title, the program will not work.
That's because in the line

zip -qr C:\Backup\\06.0 7.2008\BackUp@_ 01.02.03.zip C:\test\test 2\\

the shell (or whatever split the above line into separate arguments) has no
way of knowing that "C:\test\te st" and "2\\" are intended to be one
argument. Use subprocess.call () instead of os.system(). You can pass it a
list an thus avoid the ambiguity:

zip_command = ["zip", "-qr", target] + source
subprocess.call (zip_command)

Peter

Jun 2 '07 #3
Wow, great!! That worked like a charm. Sorry about the excessive
commenting, when looking it over I could see how that would be
annoying. Thank you Peter!

Luke

Jun 4 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
6197
by: ScottH | last post by:
I am running 7.2 with fixpack 10a under W2K. I got a backup from someone else in an attempt to debug a data issue. The other person created the database with UTF-8 (codepage 1208), so I created a new database with that codepage, cd to the directory where the backup was located, but the restore failed: db2 => create database MYDB using codeset UTF-8 territory us DB20000I The CREATE DATABASE command completed successfully. db2 =>...
6
4739
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much appreciated. Thanks in advance
0
1367
by: Mythran | last post by:
I'm getting this error and Microsoft's site states that the way we are using our libraries is unsupported and the error is by design (go figure). My setup is simple and why it isn't supported is completely unclear to me. 1.) 2 Web Sites in solution, 1 DAL library, 1 BLL library, 1 Schema library (all in same solution). 2.) DAL and BLL libraries are inheriting ServicedComponent, referencing and importing System.EnterpriseServices,...
25
2842
by: n3crius | last post by:
hi, i just got a web host with asp.net , seemed really cool. aspx with the c# or vb IN the actual main page run fine, but when i use codebehind and make another source file ( a .cs) to go with the aspx (as you would realistically) I get this : Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root...
5
2928
by: Stu Carter | last post by:
Hi, ENV: Windows 2003 Server SP1 (+all updates), VS 2003, .Net 1.1 SP1 We've got an ASP.Net web application using State Service. All is fine until we tried to use the app through a virtual directory with a space in it. e.g. 'http://localhost/My%20App'. The following exception is thrown: ----------
21
6877
by: one2001boy | last post by:
PostMessage() function returns ERROR_NOT_ENOUGH_QUOTA after running in a loop for 700 times, but the disk space and memory are still big enough. any suggestion to resolve this problem? thanks.
0
9796
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted by the software in your host machine. Stack Trace at System.Net.Sockets.NetworkStream.Write(Byte buffer, Int32 offset, Int32
9
11760
by: guitonoklops9 | last post by:
I am very new to python and programming. Right now I'm working on this simple backup program: #C:\python25\programs\ # File name: test import os, time source = target_directory = 'C:/Backup/' today = target_directory + time.strftime('%m.%d.%Y')
11
5579
by: xenoix | last post by:
hey there, im reasonably new to C# and im currently writing a backup application which im using as a learning resource. My PC :- Visual Studio 2005 .NET Framework 2 Component Factory Krypton Tools Test PC :- .Net Framework 2
0
8485
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8403
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8605
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8677
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7446
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6238
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4417
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2819
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2062
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.