Hi im very new to python, im try to get something very basic to work.
What i want is to run a python script that will fish out all the tga files in the folders and move them into the root folder. Just move them one level up. The python script will be on the root folder so you can use it current location?
to move the folders into.
Generically, a script like this will do something along the lines of
import os
import shutil
import sys
# this does the actual work
def move_files_by_pattern (pattern, sourcefolder, targetfolder):
for path, folders, files in os.walk(sourcefolder):
print files
for eachfile in files:
if pattern in eachfile:
shutil.move(path + "/" + eachfile, targetfolder)
print eachfile
# this makes it work from the commandline
if __name__ == '__main__':
pattern = sys.argv[1]
sourcefolder = sys.argv[2]
targetfolder = sys.argv[3]
move_files_by_pattern (pattern, sourcefolder, targetfolder)
# call something like "c:\path o\python.exe move_files_by_pattern.py tga path o\src path o arget
This coves generic find-and-move behavior, it’s easy to add some logic to limit it or customize it once you see how this works.
Generically, a script like this will do something along the lines of
import os
import shutil
import sys
# this does the actual work
def move_files_by_pattern (pattern, sourcefolder, targetfolder):
for path, folders, files in os.walk(sourcefolder):
print files
for eachfile in files:
if pattern in eachfile:
shutil.move(path + "/" + eachfile, targetfolder)
print eachfile
# this makes it work from the commandline
if __name__ == '__main__':
pattern = sys.argv[1]
sourcefolder = sys.argv[2]
targetfolder = sys.argv[3]
move_files_by_pattern (pattern, sourcefolder, targetfolder)
# call something like "c:\path o\python.exe move_files_by_pattern.py tga path o\src path o arget
This coves generic find-and-move behavior, it’s easy to add some logic to limit it or customize it once you see how this works.[/QUOTE]
Thanks “Theodox”
but im really stuck i have trying to figure this out for the past 4hours, im very new to python so have no clue.
i think thats easiest way from me to get this work. If i dump the py script file into the root folder then i can use “os.getcwd()” to get the path to:
-1 search into the dir to find tga’s
-2 to move the tga’s into
just looking for a very fast simple solution, sorry just kind of lost with this