Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need Help for my program
#1
Hi friends
I am new to python. i tried to write a code for file transfer automation.
actually my requirement is software will generate a folder daily with the name of today's date in server. And inside this folder some other sub folders also created automatically. I should check whether folder was created with today's date. if created then have to check the sub folders on e by one. if the date folder not found program should exit.
pls help me to complete the program.
my coding is....

import os, sys
import os.path
from datetime import date


folder = today.strftime("%Y-%m-%d")

mydir = os.path.exists('/xxx/yyy/zzz/'+ folder)

if mydir == True:

print(str(mydir))
print("yes exists")

dirname = '/xxx/yyy/zzz/{folder}'
filename = 'folder_1, folder_2, folder_3'
#check directory exists
print(dirname)
print(filename)
if(os.path.exists(filename)):
print("Directory Exists")
print(dirname)
else:
print("Directory does not exists")

#check file exists
Reply
#2
Can you please elaborate the difficulty or error that you are facing
Reply
#3
thanks for your reply MALT.

In the server if the folder with the name of today's date was exists then have to check the folders inside that created date folder folder.

example:
folder = today.strftime("%Y-%m-%d")

mydir = os.path.exists('/xxx/yyy/zzz/'+ folder)

" In this, folder name would be 2019-11-27 "
my question is, after this how should i check whether particular folders(ex: folderx, foldery, folderz) found inside the folder 2019-11-27.

Thanks in advance....
Reply
#4
Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
Please help me to complete the program.
Reply
#6
(Nov-27-2019, 07:38 AM)sampathkumar Wrote: thanks for your reply MALT.

In the server if the folder with the name of today's date was exists then have to check the folders inside that created date folder folder.

example:
folder = today.strftime("%Y-%m-%d")

mydir = os.path.exists('/xxx/yyy/zzz/'+ folder)

" In this, folder name would be 2019-11-27 "
my question is, after this how should i check whether particular folders(ex: folderx, foldery, folderz) found inside the folder 2019-11-27.

Thanks in advance....

Do you want to check only the existence of the sub folders? or you want to validate any file in it? And those sub folders will be constant or will vary?

If you want to check only for sub folder existence, you can very well use the
os.path.exists
parent_dir = "/xxx/yyy/zzz/"
folder = today.strftime("%Y-%m-%d")
directory_path = os.path.join(parent_dir, folder)
if os.path.exists(directory_path):
    <check for sub folders>
else: print("Folder doesn't exists")
[/python]
Reply
#7
Thanks for your reply Mr.MALT

this code is very useful for me.

sub folder was not constant it is also created one by one at certain time interval. maximum 4 folders will be created.

if sub folders found, files inside that sub folders should be copied to another location with the same 4 folder names which was already created.

example:

server1 server2
/xxx/yyy/zzz/datefolder/ /aaa/bbb/ccc/

folder1 --- > folder1
folder2 ----> folder2
folder3 ----> folder3
folder4 ----> folder4

Thanks in advance....
Reply
#8
In that case how will you cross verify whether all the sub folders are created or not?. You can use Python shutil.copy() method to copy from source to destination
Reply
#9
(Dec-03-2019, 09:13 AM)Malt Wrote: In that case how will you cross verify whether all the sub folders are created or not?. You can use Python shutil.copy() method to copy from source to destination

Ya. shutil.copy() is used currently. But it was manually running the program until all the sub folders created.

For automating this only i need a program.

Program should keep on checking for that 4 folders until it created. folder names are constant only. once it is created then files inside that folders to be copied to another location individually. also it should keep on searching the files in that folders . once files comes then it should be automatically copied to destination path.

pls help me Mr.Malt.

Thanks in advance....
Reply
#10
I can suggest you a logic, you can have a flag and make the flag to turn True when all the expected sub folders are available. Till then it has to keep checking the folders availability. Here we are having a check, when any folder creation fails then it will keep on waiting and checking endlessly.

To avoid that you can have a timer, either timer should expire or your condition should meet. After meeting either of the case, your next step which is copying the sub folders to another location should take place.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020