How can i copy and move all Folder which are older than 30 days to a _History folder?How to get file creation & modification date/times in Python?How to copy files from 'assets' folder to sdcard?Difference between shutil.copy2(s,d) and shutil.move(s,d)How to copy a folder from remote to local using scp?Copy Files From List PythonIs it possible to move a file with python, that has been uploaded with php (tmp_name in mind)?Find files by creation/modification date then moving to another dir in PythonHow can I move file to a folder based on a year value that is part of the filenameRename and move file with PythonUsing os.walk to get all files from dir and its subdirsPython import module from directory
In SQL Server, why does backward scan of clustered index cannot use parallelism?
Plausibility of Ice Eaters in the Arctic
Is it incorrect to write "I rate this book a 3 out of 4 stars?"
What are the advantages and disadvantages of Wand of Cure Light Wounds and Wand of Infernal Healing compared to each other?
As a 16 year old, how can I keep my money safe from my mother?
A tool to replace all words with antonyms
What happen to those who died but not from the snap?
Identification of vintage sloping window
What is the difference between TAS and GS?
Double redundancy for the Saturn V LVDC computer memory, how were disagreements resolved?
English - Acceptable use of parentheses in an author's name
Visa National - No Exit Stamp From France on Return to the UK
How to create all combinations from a nested list while preserving the structure using R?
How does 'AND' distribute over 'OR' (Set Theory)?
What should I call bands of armed men in Medieval Times?
Are differences between uniformly distributed numbers uniformly distributed?
Why did the RAAF procure the F/A-18 despite being purpose-built for carriers?
What costs less energy? Roll or Yaw?
Infeasibility in mathematical optimization models
The cat ate your input again!
How are you supposed to know the strumming pattern for a song from the "chord sheet music"?
Are there any financial disadvantages to living significantly "below your means"?
Should I ask for permission to write an expository post about someone's else research?
What does Apple mean by "This may decrease battery life"?
How can i copy and move all Folder which are older than 30 days to a _History folder?
How to get file creation & modification date/times in Python?How to copy files from 'assets' folder to sdcard?Difference between shutil.copy2(s,d) and shutil.move(s,d)How to copy a folder from remote to local using scp?Copy Files From List PythonIs it possible to move a file with python, that has been uploaded with php (tmp_name in mind)?Find files by creation/modification date then moving to another dir in PythonHow can I move file to a folder based on a year value that is part of the filenameRename and move file with PythonUsing os.walk to get all files from dir and its subdirsPython import module from directory
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Structure: 20170410.1207.te <- Date (2017 04 10 , 12:07)
There is a company folder that contains several folders. All folders with the above structure which are older than 30 days should be moved to the folder _History
(basically archiving them), but at least 5 should be left no matter which timestamp.
As a time value, the string must be taken from the folder name to be converted as a date and compared to today's date minus 30 days.
I also want to create a log file that logs when which folders were moved at what location.
The Code below just shows me the filename, can somebody help me please?
import os
import shutil
for subdir, dirs, files in os.walk("C:Python-ScriptSpielwiese"):
for file in files:
print(os.path.join(file))
shutil.move("C:Python-ScriptSpielwiese", "C:Python-ScriptSpielwiese2")
python copy move
add a comment |
Structure: 20170410.1207.te <- Date (2017 04 10 , 12:07)
There is a company folder that contains several folders. All folders with the above structure which are older than 30 days should be moved to the folder _History
(basically archiving them), but at least 5 should be left no matter which timestamp.
As a time value, the string must be taken from the folder name to be converted as a date and compared to today's date minus 30 days.
I also want to create a log file that logs when which folders were moved at what location.
The Code below just shows me the filename, can somebody help me please?
import os
import shutil
for subdir, dirs, files in os.walk("C:Python-ScriptSpielwiese"):
for file in files:
print(os.path.join(file))
shutil.move("C:Python-ScriptSpielwiese", "C:Python-ScriptSpielwiese2")
python copy move
So, first thing: How do you want to determine the age of the files? Windows' creation date? An answer on how to do this can be found here: stackoverflow.com/questions/237079/…
– Dschoni
Mar 27 at 8:35
Yes with the Windows Creation Date.
– YungCarti
Mar 27 at 8:36
@YungCarti Please comment in English only as this comment will only provide additional information/clarification for individuals able to read/understand German language..
– iLuvLogix
Mar 27 at 8:47
@iLuvLogix 20170410.1207.te There is a company folder that contains several folders. All folders with the above structure should be moved to the folder _History, which are older than 30 days but at least 5 should be left no matter which timestamp. As a time value, the string must be taken from the folder name to be converted as a date and compared to today's date - 30 days. Also create a log file that writes what and where has been delete
– YungCarti
Mar 27 at 9:04
add a comment |
Structure: 20170410.1207.te <- Date (2017 04 10 , 12:07)
There is a company folder that contains several folders. All folders with the above structure which are older than 30 days should be moved to the folder _History
(basically archiving them), but at least 5 should be left no matter which timestamp.
As a time value, the string must be taken from the folder name to be converted as a date and compared to today's date minus 30 days.
I also want to create a log file that logs when which folders were moved at what location.
The Code below just shows me the filename, can somebody help me please?
import os
import shutil
for subdir, dirs, files in os.walk("C:Python-ScriptSpielwiese"):
for file in files:
print(os.path.join(file))
shutil.move("C:Python-ScriptSpielwiese", "C:Python-ScriptSpielwiese2")
python copy move
Structure: 20170410.1207.te <- Date (2017 04 10 , 12:07)
There is a company folder that contains several folders. All folders with the above structure which are older than 30 days should be moved to the folder _History
(basically archiving them), but at least 5 should be left no matter which timestamp.
As a time value, the string must be taken from the folder name to be converted as a date and compared to today's date minus 30 days.
I also want to create a log file that logs when which folders were moved at what location.
The Code below just shows me the filename, can somebody help me please?
import os
import shutil
for subdir, dirs, files in os.walk("C:Python-ScriptSpielwiese"):
for file in files:
print(os.path.join(file))
shutil.move("C:Python-ScriptSpielwiese", "C:Python-ScriptSpielwiese2")
python copy move
python copy move
edited Mar 27 at 9:44
YungCarti
asked Mar 27 at 8:26
YungCartiYungCarti
11 bronze badge
11 bronze badge
So, first thing: How do you want to determine the age of the files? Windows' creation date? An answer on how to do this can be found here: stackoverflow.com/questions/237079/…
– Dschoni
Mar 27 at 8:35
Yes with the Windows Creation Date.
– YungCarti
Mar 27 at 8:36
@YungCarti Please comment in English only as this comment will only provide additional information/clarification for individuals able to read/understand German language..
– iLuvLogix
Mar 27 at 8:47
@iLuvLogix 20170410.1207.te There is a company folder that contains several folders. All folders with the above structure should be moved to the folder _History, which are older than 30 days but at least 5 should be left no matter which timestamp. As a time value, the string must be taken from the folder name to be converted as a date and compared to today's date - 30 days. Also create a log file that writes what and where has been delete
– YungCarti
Mar 27 at 9:04
add a comment |
So, first thing: How do you want to determine the age of the files? Windows' creation date? An answer on how to do this can be found here: stackoverflow.com/questions/237079/…
– Dschoni
Mar 27 at 8:35
Yes with the Windows Creation Date.
– YungCarti
Mar 27 at 8:36
@YungCarti Please comment in English only as this comment will only provide additional information/clarification for individuals able to read/understand German language..
– iLuvLogix
Mar 27 at 8:47
@iLuvLogix 20170410.1207.te There is a company folder that contains several folders. All folders with the above structure should be moved to the folder _History, which are older than 30 days but at least 5 should be left no matter which timestamp. As a time value, the string must be taken from the folder name to be converted as a date and compared to today's date - 30 days. Also create a log file that writes what and where has been delete
– YungCarti
Mar 27 at 9:04
So, first thing: How do you want to determine the age of the files? Windows' creation date? An answer on how to do this can be found here: stackoverflow.com/questions/237079/…
– Dschoni
Mar 27 at 8:35
So, first thing: How do you want to determine the age of the files? Windows' creation date? An answer on how to do this can be found here: stackoverflow.com/questions/237079/…
– Dschoni
Mar 27 at 8:35
Yes with the Windows Creation Date.
– YungCarti
Mar 27 at 8:36
Yes with the Windows Creation Date.
– YungCarti
Mar 27 at 8:36
@YungCarti Please comment in English only as this comment will only provide additional information/clarification for individuals able to read/understand German language..
– iLuvLogix
Mar 27 at 8:47
@YungCarti Please comment in English only as this comment will only provide additional information/clarification for individuals able to read/understand German language..
– iLuvLogix
Mar 27 at 8:47
@iLuvLogix 20170410.1207.te There is a company folder that contains several folders. All folders with the above structure should be moved to the folder _History, which are older than 30 days but at least 5 should be left no matter which timestamp. As a time value, the string must be taken from the folder name to be converted as a date and compared to today's date - 30 days. Also create a log file that writes what and where has been delete
– YungCarti
Mar 27 at 9:04
@iLuvLogix 20170410.1207.te There is a company folder that contains several folders. All folders with the above structure should be moved to the folder _History, which are older than 30 days but at least 5 should be left no matter which timestamp. As a time value, the string must be taken from the folder name to be converted as a date and compared to today's date - 30 days. Also create a log file that writes what and where has been delete
– YungCarti
Mar 27 at 9:04
add a comment |
1 Answer
1
active
oldest
votes
The following code will return a list of all files in a given timeframe, sorted by create time on windows. Depending on how you want to filter, I can give you more information. You can than work on the resulting list. One more thing is, that you should use pathlib
for windows filepaths, to not run into problems with german paths and unicode escapes in your pathname.
import os
import shutil
found_files = []
for subdir, dirs, files in os.walk("C:Python-ScriptSpielwiese"):
for file in files:
name = os.path.join(file)
create_date = os.path.getctime(file)
if create_date > some_time: # Put the timeframe here
found_files.append((name, create_date))
found_files.sort(key=lambda tup: tup[1]) # Sort the files according to creation time
how do I specify the time frame?
– YungCarti
Mar 27 at 11:49
you set some time, using e.g.datetime.now()
or some other point in time using thetime
ordatetime
package.
– Dschoni
Mar 28 at 12:47
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55372668%2fhow-can-i-copy-and-move-all-folder-which-are-older-than-30-days-to-a-history-fo%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The following code will return a list of all files in a given timeframe, sorted by create time on windows. Depending on how you want to filter, I can give you more information. You can than work on the resulting list. One more thing is, that you should use pathlib
for windows filepaths, to not run into problems with german paths and unicode escapes in your pathname.
import os
import shutil
found_files = []
for subdir, dirs, files in os.walk("C:Python-ScriptSpielwiese"):
for file in files:
name = os.path.join(file)
create_date = os.path.getctime(file)
if create_date > some_time: # Put the timeframe here
found_files.append((name, create_date))
found_files.sort(key=lambda tup: tup[1]) # Sort the files according to creation time
how do I specify the time frame?
– YungCarti
Mar 27 at 11:49
you set some time, using e.g.datetime.now()
or some other point in time using thetime
ordatetime
package.
– Dschoni
Mar 28 at 12:47
add a comment |
The following code will return a list of all files in a given timeframe, sorted by create time on windows. Depending on how you want to filter, I can give you more information. You can than work on the resulting list. One more thing is, that you should use pathlib
for windows filepaths, to not run into problems with german paths and unicode escapes in your pathname.
import os
import shutil
found_files = []
for subdir, dirs, files in os.walk("C:Python-ScriptSpielwiese"):
for file in files:
name = os.path.join(file)
create_date = os.path.getctime(file)
if create_date > some_time: # Put the timeframe here
found_files.append((name, create_date))
found_files.sort(key=lambda tup: tup[1]) # Sort the files according to creation time
how do I specify the time frame?
– YungCarti
Mar 27 at 11:49
you set some time, using e.g.datetime.now()
or some other point in time using thetime
ordatetime
package.
– Dschoni
Mar 28 at 12:47
add a comment |
The following code will return a list of all files in a given timeframe, sorted by create time on windows. Depending on how you want to filter, I can give you more information. You can than work on the resulting list. One more thing is, that you should use pathlib
for windows filepaths, to not run into problems with german paths and unicode escapes in your pathname.
import os
import shutil
found_files = []
for subdir, dirs, files in os.walk("C:Python-ScriptSpielwiese"):
for file in files:
name = os.path.join(file)
create_date = os.path.getctime(file)
if create_date > some_time: # Put the timeframe here
found_files.append((name, create_date))
found_files.sort(key=lambda tup: tup[1]) # Sort the files according to creation time
The following code will return a list of all files in a given timeframe, sorted by create time on windows. Depending on how you want to filter, I can give you more information. You can than work on the resulting list. One more thing is, that you should use pathlib
for windows filepaths, to not run into problems with german paths and unicode escapes in your pathname.
import os
import shutil
found_files = []
for subdir, dirs, files in os.walk("C:Python-ScriptSpielwiese"):
for file in files:
name = os.path.join(file)
create_date = os.path.getctime(file)
if create_date > some_time: # Put the timeframe here
found_files.append((name, create_date))
found_files.sort(key=lambda tup: tup[1]) # Sort the files according to creation time
answered Mar 27 at 11:34
DschoniDschoni
1,55324 silver badges51 bronze badges
1,55324 silver badges51 bronze badges
how do I specify the time frame?
– YungCarti
Mar 27 at 11:49
you set some time, using e.g.datetime.now()
or some other point in time using thetime
ordatetime
package.
– Dschoni
Mar 28 at 12:47
add a comment |
how do I specify the time frame?
– YungCarti
Mar 27 at 11:49
you set some time, using e.g.datetime.now()
or some other point in time using thetime
ordatetime
package.
– Dschoni
Mar 28 at 12:47
how do I specify the time frame?
– YungCarti
Mar 27 at 11:49
how do I specify the time frame?
– YungCarti
Mar 27 at 11:49
you set some time, using e.g.
datetime.now()
or some other point in time using the time
or datetime
package.– Dschoni
Mar 28 at 12:47
you set some time, using e.g.
datetime.now()
or some other point in time using the time
or datetime
package.– Dschoni
Mar 28 at 12:47
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55372668%2fhow-can-i-copy-and-move-all-folder-which-are-older-than-30-days-to-a-history-fo%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
So, first thing: How do you want to determine the age of the files? Windows' creation date? An answer on how to do this can be found here: stackoverflow.com/questions/237079/…
– Dschoni
Mar 27 at 8:35
Yes with the Windows Creation Date.
– YungCarti
Mar 27 at 8:36
@YungCarti Please comment in English only as this comment will only provide additional information/clarification for individuals able to read/understand German language..
– iLuvLogix
Mar 27 at 8:47
@iLuvLogix 20170410.1207.te There is a company folder that contains several folders. All folders with the above structure should be moved to the folder _History, which are older than 30 days but at least 5 should be left no matter which timestamp. As a time value, the string must be taken from the folder name to be converted as a date and compared to today's date - 30 days. Also create a log file that writes what and where has been delete
– YungCarti
Mar 27 at 9:04