Hi
I need your help. I'm a complete Bash-script noob.
I want a script that moves file to a different folder, only pdf files.
For example:
SAb downloads a file and extract it to folder /volume1/Downloads. After the extraction it looks like this: /volume1/Downloads/NAMEofNewspaper/NAMEandDATE/newspaper.pdf
The script should move the pdf in a different folder like /volume1/Newspapers
Additional: It would be awesome if the script could automatically delete all the other stuff including the empty folders and rename the pdf file after the folder it was in. For example the pdf file above should be rename into NAMEandDATE.pdf.
Please help me!
Move-Script for pdf (Newspaper)
Re: Move-Script for pdf (Newspaper)
I tryed a lot and i was successfull with the movement-part, but is still can't figure out how to rename it proberly. I'm still hoping for your help.
Here is my Python script to move files (recursiv) with specific suffix;
Here is my Python script to move files (recursiv) with specific suffix;
Code: Select all
import os, shutil, sys
srcDir = '/volume1/web/Library/'
dstDir = '/volume1/dropbox/Kindle/'
extension = '.pdf'
print "Source Dir: ", srcDir, "n", "Destination Dir: ",dstDir, "n", "Extension: ", extension
for root, dirs, files in os.walk(srcDir):
for file_ in files:
if file_.endswith(extension):
shutil.copy(os.path.join(root, file_), os.path.join(dstDir, file_))
Re: Move-Script for pdf (Newspaper)
Cool! You've written your own script, and in python. Bravo. Oh: the script actually works within SAB?
If so, I will help you with the renaming:
Input: /volume1/Downloads/NAMEofNewspaper/NAMEandDATE/newspaper.pdf
Output: NAMEandDATE.pdf.
Correct? If so, I'll write it for you.
If so, I will help you with the renaming:
Input: /volume1/Downloads/NAMEofNewspaper/NAMEandDATE/newspaper.pdf
Output: NAMEandDATE.pdf.
Correct? If so, I'll write it for you.
Re: Move-Script for pdf (Newspaper)
Here it is:
Result:
Does this help?
Code: Select all
name ='/volume1/Downloads/NAMEofNewspaper/NAMEandDATE/newspaper.pdf'
print name
dirname = name.split('/')[-2]
newfilename = dirname + '.pdf'
print newfilename
Code: Select all
$ python rename.py
/volume1/Downloads/NAMEofNewspaper/NAMEandDATE/newspaper.pdf
NAMEandDATE.pdf
Re: Move-Script for pdf (Newspaper)
thank you very much, this helps me a lot, but i still have one question. This path is variable, because i download different newspapers, so is is possible to use something like this to channge the path of the file for every new file?
I tryed this: "os.path.dirname(os.path.realpath(__file__))" but this uses the path of my Sabnzbd installfolder.
Maybe i should mention that i use a synolgy nas and python 2.7.3.
Code: Select all
/volume1/Downloads/NAMEofNewspaper/NAMEandDATE/newspaper.pdf
Code: Select all
name = Variable Path to pdf file
print name
dirname = name.split('/')[-2]
newfilename = dirname + '.pdf'
print newfilename
Maybe i should mention that i use a synolgy nas and python 2.7.3.
Re: Move-Script for pdf (Newspaper)
I don't understand what you don't understand.
I don't understand the purpose of the second piece of code you gave
I don't understand the purpose of the line "os.path.dirname"
I don't understand the purpose of the second piece of code you gave
I don't understand the purpose of the line "os.path.dirname"