473,322 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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\BackUp@_10.03.57.zip . -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\programs\
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_directory = 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_directory + 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(today, 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_command) == 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 2056
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\BackUp@_10.03.57.zip . -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\programs\
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_directory = 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_directory + 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(today, 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_command) == 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.07.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\test" 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
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...
6
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...
0
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...
25
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...
5
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...
21
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
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...
9
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 =...
11
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.