Results 1 to 7 of 7

Thread: Copy, move, rename file via programming

  1. #1
    Join Date
    Mar 2009
    Posts
    1,221

    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

  2. #2
    Join Date
    Nov 2008
    Posts
    1,192

    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 { } \;

  3. #3
    Join Date
    Mar 2009
    Posts
    1,221

    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?

  4. #4
    Join Date
    Nov 2008
    Posts
    1,192

    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) ...

  5. #5
    Join Date
    Mar 2009
    Posts
    1,221

    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?

  6. #6
    Join Date
    Nov 2008
    Posts
    1,192

    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

  7. #7
    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.

Similar Threads

  1. Replies: 5
    Last Post: 13-06-2012, 02:04 PM
  2. Replies: 3
    Last Post: 23-10-2011, 05:17 PM
  3. Batch File to Move or Copy Files
    By Pratim in forum Windows Software
    Replies: 6
    Last Post: 21-03-2010, 09:32 PM
  4. Replies: 9
    Last Post: 20-03-2008, 08:44 PM
  5. Autorun.inf cannot copy/move.
    By Ray Stanley in forum Windows Server Help
    Replies: 8
    Last Post: 08-08-2005, 08:38 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,943,535.61279 seconds with 17 queries