0

GITHUB

Hi,

This is a pretty basic script i have started in python..

I intend to eventually, in nyears to come lol, to use it to backup from my server(FTP) to my local backup drive (E), then backup again to my other Local backup drive (D:).

So far im buzzing..

I managed to copy using copytree from a directory i specify in the script to another directory that i specify in the script..

Local E: to local D:..

my next task, well next mission is to be able to Input the directory i wish to copy from and copy to..

i assumed this would be as simplae as chanhging the

src =

to

src = input()

alas this causes an error..

anyways here is the script and i would appreciate any input as Python, so fun is still an alien langauge to me lol..

import shutil, os, datetime, time, sys

newFolderName = datetime.datetime.now()
newFolder = newFolderName.strftime('%m%d%Y')

  src = input('type the src dir: ')
  dst= input('type the dest dir: ' +
           newFolderName.strftime('%d-%B-%y\\').upper())

shutil.copytree(src, dst)
johnashu
  • 2,167
  • 4
  • 19
  • 44
  • that worked a charm.. import shutil, os, datetime, time, sys newFolderName = datetime.datetime.now() newFolder = newFolderName.strftime('%m%d%Y') src = ('E:\\COPY\\') dst = ('D:\\COPY\\' + newFolderName.strftime('%d-%B-%y\\').upper()) shutil.copytree(src, dst) – johnashu Apr 13 '17 at 23:04
  • sorry im getting used to the comments here.. enter adds a new meesage it seems! this is the error i receive when i change the src and dst to src = input('') – johnashu Apr 13 '17 at 23:07
  • W >>> >>> shutil.copytree(src, dst) Traceback (most recent call last): File "", line 1, in File "C:\Users\John\AppData\Local\Programs\Python\Python36-32\lib\shutil.py", line 309, in copytree names = os.listdir(src) OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: "d st = ('D:\\\\COPY\\\\' +" – johnashu Apr 13 '17 at 23:07
  • thats the Error when i Try and use data for a user input.. my main problem with python scripting which i really need the answer to is when asking for input how do i stop the script until the input is registered and available to be called.. its driving me crazY!! i want it to read and execute like this.. src = input('type the source dir') dest = input('type the dest dir') i have the same issue with an FTP login scipt im trying to write.. ftp_add = input('ftp address:') username = input('username:') password = input('password:') – johnashu Apr 14 '17 at 00:01
  • i have changed the dir to being in ' ' . it makes it so much easier to read.. – johnashu Apr 14 '17 at 00:03
  • src = ('E:' 'COPY') dst = ('D:' 'COPY' – johnashu Apr 14 '17 at 00:03
  • its amazing how much unnecessary code i started of with.. thanks for the time! – johnashu Apr 14 '17 at 00:04
  • i still dont know how to allow user input to be registered before the script carries on. i can only acheive this manually... line by line is there not some sort of STOP WAIT AMINUTE FOR THE USER INPUT command i can execute? – johnashu Apr 14 '17 at 00:09
  • i swear thats what im doing. im gonna try copy and paste what you posted src = input("'type the dest dir: ') python 3.6 btw – johnashu Apr 14 '17 at 00:27
  • no that didnt work.. when i run the script it ignores the commands – johnashu Apr 14 '17 at 00:29
  • the input command that is.. – johnashu Apr 14 '17 at 00:29
  • if i manuyally enter in the interperetor it runs fine.. if i try and run it as a script.. it crashes! – johnashu Apr 14 '17 at 00:33
  • i have changed it to what i want lol – johnashu Apr 14 '17 at 00:36
  • no i mean the current edited code "READS" like what i want it to do lol.. it does nothing at the moment – johnashu Apr 14 '17 at 00:38
  • that link has the same problem.. line by line it is fine.. executing the script it is not so fine! – johnashu Apr 14 '17 at 00:39
  • i have the exact same problem with this script here. look at the second code snippet http://stackoverflow.com/questions/43403377/how-do-i-connect-to-ftp-without-password-in-the-script – johnashu Apr 14 '17 at 00:41
  • im running it locally – johnashu Apr 14 '17 at 00:41
  • i have xampp running for PHP... – johnashu Apr 14 '17 at 00:41
  • i want to allow the user to input the src and dest then run the shutil.copytree(src, dst) with the values that have been inputted – johnashu Apr 14 '17 at 00:56
  • im afraid that either didnt make sense to me or didnt work lol – johnashu Apr 14 '17 at 01:07
  • it works perfectly line by line – johnashu Apr 14 '17 at 01:19
  • "sorry about that, i mean in your script, can you get any user input using only these 2 lines: src = input('type the src dir: '); print(src) ? " No nothing at all.. only the input line.. – johnashu Apr 14 '17 at 01:22
  • like if i put this in src = input('type the src dir: ') then it runs or if it is the last line – johnashu Apr 14 '17 at 01:23
  • do you think maybe it is a problem with ython install? – johnashu Apr 14 '17 at 01:23
  • import shutil, os, datetime, time, sys newFolderName = datetime.datetime.now() newFolder = newFolderName.strftime('%m%d%Y') src = input('type the src dir: ') dst = input('type the dest dir: ' + newFolderName.strftime('%d-%B-%y\\').upper()) shutil.copytree(src, dst) *********************************************************** if i type that into the interpreter line by line it works 100% fine – johnashu Apr 14 '17 at 01:25
  • i like to use the interperater as im still learning.. it helps to keep me right as you know there and then what works and what doesnt.. i suppose it comes from linux bashing lol. im happy with writing scripts but i just cant get them to run. im happy enough that they do work.. have you tried running the script? is it just me? – johnashu Apr 14 '17 at 01:32
  • its the craziest thing.. i literally uninstalled python.. i erased every trace from the registry the hd, rebooted and reloaded twice.. and still unless i type line by line it wont run.. im totally new to python.. i can code but i cant troubleshoot this lol – johnashu Apr 14 '17 at 02:17
  • honmestly xammp is nothingness – johnashu Apr 14 '17 at 02:21
  • import shutil, os, datetime, time, sys newFolderName = datetime.datetime.now() newFolder = newFolderName.strftime('%m%d%Y') src = input('type the src dir: ') dst = input('type the dest dir: ' + newFolderName.strftime('%d-%B-%y\\').upper()) shutil.copytree(src, dst) this is what should work... if i type it line by line it works.. if i run it as a script it doesnt work because it doesnt take in any input – johnashu Apr 14 '17 at 02:23
  • only line by line in pythonn 3.6 – johnashu Apr 14 '17 at 02:36
  • when using he interperter not running a script.. thats my problem.. scripts wont run correctly – johnashu Apr 14 '17 at 02:37
  • all commands work fine unless user input is required. if i repolace what the input commands are with the actual required data, then the scrip[t runs fine.... – johnashu Apr 14 '17 at 02:41
  • this script runs fine***************** import shutil, os, datetime, time, sys newFolderName = datetime.datetime.now() newFolder = newFolderName.strftime('%m%d%Y') src = ('E:' 'COPY') dst = ('D:' 'COPY' + newFolderName.strftime('%d-%B-%y\\').upper()) shutil.copytree(src, dst) – johnashu Apr 14 '17 at 02:42
  • change it to require user input and it doesnt*********************import shutil, os, datetime, time, sys newFolderName = datetime.datetime.now() newFolder = newFolderName.strftime('%m%d%Y') src = input('type the src dir: ') dst = input('type the dest dir: ' + newFolderName.strftime('%d-%B-%y\\').upper()) shutil.copytree(src, dst) – johnashu Apr 14 '17 at 02:42
  • if i execute the user input script, line-by-line or type it in 1 charachter at a time then it runs perfectly – johnashu Apr 14 '17 at 02:43
  • the script skips past every user input request without requesting anything – johnashu Apr 14 '17 at 02:43
  • im 100#% running python 3.6 BUTTTTTTTTTTT>>>> I did have 2.7 on before that and i did clean every trace i could find but now im realy really not sure – johnashu Apr 14 '17 at 02:56
  • the scripts are runnnign – johnashu Apr 14 '17 at 03:01
  • it was me all along.or a possible dodgy install – johnashu Apr 14 '17 at 03:01
  • yeah you might want to hunt down and fix any buggy install for future python use, doubt you'll want to use magic anytime you expect python to work, but sounds like for this issue, you got it working! congrats buddy! – chickity china chinese chicken Apr 14 '17 at 03:04
  • i think the seek and destroy effort from eariler may have contributed to this solve.. – johnashu Apr 14 '17 at 03:05
  • but thanks for sticking to logic with me and trying to solve a seemingly impossible problem.. patience it a virtue my friend :)( – johnashu Apr 14 '17 at 03:06
  • no problem.. im on to the next task if you wish to contribute.. no magic this time :) http://stackoverflow.com/questions/43404660/how-do-i-know-whats-going-on-with-the-file-copy – johnashu Apr 14 '17 at 03:12
  • i think a little bit of magic, a little bad code and a bit of user Error was in playu – johnashu Apr 14 '17 at 03:13
  • yep, that's the idea behind this "community", try to help each other out. you too, stay cool bro, cheers – chickity china chinese chicken Apr 14 '17 at 03:16

0 Answers0