Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , ,

Sponsored Links



Copy, move, rename file via programming

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 14-11-2009
Member
 
Join Date: Mar 2009
Posts: 1,233
Copy, move, rename file via programming

I want to automate recurrent tasks (i.e. Copy, move, rename file) to save time. If only it were simple data processing! I do not know programming. It seems that the batch is best suited for this kind of manip. I have it yet:

Code:
                folder xxx 
                /          \ 
     folder yy            folder zz 
       /      \                /     \ 
   folder  folder       folder   folder
  Jpeg      Dng        Jpeg     Dng 
    |           |             |        | 
   file         file         file      file    
   jpg        Dng          jpg      Dng

Let me get this:

Code:
               folder xxx 
                /          \ 
       folder yy       folder zz 
           |                  | 
          file                file 
          jpg                jpg
After viewing, I think that was understandable. But tell me if you do not. I cast my eye on the next batch commands to try to do something but there is no explanation on the precise syntax. There's just commands.

I come hard to know how but I think this could work:
1. Delete all files except the file xxx. Jpg
2. Moving JPEG files in their parent folder
3. Delete empty folders
Reply With Quote
  #2  
Old 14-11-2009
Member
 
Join Date: Nov 2008
Posts: 1,193
Re: Copy, move, rename file via programming

to delete the file Dng
Code:
find folderxxx -name *.Dng - exec rm { } \;
to move more files
Code:
for f in $ (find folderxxx -name "*.jpg" ) ; do mv $f $ ( dirname $ ( dirname $f ) ) ; done
to remove empty directories
Code:
find folderxxx - type d -empty - exec rmdir { } \;
Reply With Quote
  #3  
Old 14-11-2009
Member
 
Join Date: Mar 2009
Posts: 1,233
Re: Copy, move, rename file via programming

But I have come not to execute the batch. I just tried to launch the first but it does not work. I put it in my batch:
Code:
@echo off
find folderxxx -name *.dng -exec rm {} \;
The name of my file is folderxxx and it is in the same folder as the batch in question. All dng are always present in the folder.

What I forgot?
Reply With Quote
  #4  
Old 14-11-2009
Member
 
Join Date: Nov 2008
Posts: 1,193
Re: Copy, move, rename file via programming

The orders I have given are unix commands, if you're on windows, recover on http://unxutils.sourceforge.net/ and then it should work (Windows has a find command that corresponds to grep unix, but not to find unix) ...
Reply With Quote
  #5  
Old 14-11-2009
Member
 
Join Date: Mar 2009
Posts: 1,233
Re: Copy, move, rename file via programming

Excuse me for my ignorance. But I can not. I get UnxUtils. So I must at first be able to apply the script. But how exactly. Does it need to execute a file in UnxUtils (there are many executable)? Do I have to UnxUtils in a particular folder? For the script, I created a xxx.bat? With the code you gave me, it must add a "@echo off" or something else?
Reply With Quote
  #6  
Old 14-11-2009
Member
 
Join Date: Nov 2008
Posts: 1,193
Re: Copy, move, rename file via programming

That may be a little complicated if you're not too comfortable with the scripts. Or when you just unzip find.exe and sed.exe, you put that part (eg d:\UnxUtils) and you call with
Code:
d:\unxutils\find.exe folderxxx -name *.dng | sed "s/^/ del /"
That generates commands back to the delete files (you redirect them to a. bat and you run, with
Code:
d:\unxutils\find.exe folderxxx -name *.dng | sed "s/^/del /" > delpng.bat
delpng.bat
it'll generate a list of files
Reply With Quote
  #7  
Old 21-03-2010
Member
 
Join Date: Dec 2009
Posts: 23
Re: Copy, move, rename file via programming

Although old post, this is in case someone in future has the same problem.

You may want to consider a biterscripting script for file manipulation like this. I wrote a quick script.

Code:
# Script DeleteAllButJPG.txt
# Deletes all files but .jpg files under root directory - $root.
var str root
var str list, file
lf -r -n -g "*" $root ($fype=="f") > $list
while ($list <> "")
do
     # Get the next file from the list.
     lex "1" $list > $file
     # Does file name end in ".jpg" ?
     if ( { stex -c "^.jpg^l]" $file }  <> $file )
        # Delete file.
        system -s del "/Q" ("\""+$file+"\"")
     endif
done

Looks big because I added comments.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Copy, move, rename file via programming"
Thread Thread Starter Forum Replies Last Post
How are the file management basics like copy, rename, move and delete in Windows 8? Mr.Aiden Operating Systems 3 23-10-2011 06:17 PM
Need to refresh while doing Delete, Rename or Move in Windows 7 x64 Man-Than Windows x64 Edition 6 13-05-2011 11:43 AM
Batch File to Move or Copy Files Pratim Windows Software 6 21-03-2010 10:32 PM
Unable to rename, move or delete folder Peter Wilkins Windows XP Support 15 01-03-2007 10:07 AM
Is it possible to disable "Calculating time to copy/move file..." Baron Vista Help 23 13-01-2007 07:05 AM


All times are GMT +5.5. The time now is 05:33 AM.