Renaming script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Renaming script
# 8  
Old 12-02-2002
Quote:
Originally posted by perleo
getting loads of errors!!!! any other idea
What type of errors are you getting?
# 9  
Old 12-02-2002
bareword found line 23 near "system" copy"
scalar found found line 23 near ${trackFolder}\


and stuff like that
# 10  
Old 12-02-2002
I made 1 mistake; so sue me ... I am doing you a favour! I have checked it and it worked on WinME!!! It's all due to the fact that Windows uses the "\" to define a folder in a path, so in Perl you have to use two of them (like: \\). This should now work:
Code:
#!/perl/bin/perl

# --------------------------------------------------------------
# Creates a backup of each file in a specified folder

#set this to the folder you want check
$trackFolder = "c:\\perl_tmp";

  opendir(TARGETFOLDER, $trackFolder);
  @files = readdir(TARGETFOLDER);
  closedir(TARGETFOLDER);

  
  $found = 0;
  

  foreach $targetFile (@files) {	  
	  # append the number 1 to any file which doesn't have it
      if ($targetFile =~ m/^1/) {
        $found = 1;
      }

    if ($found == 0) {
      system "copy ${trackFolder}\\${targetFile} ${trackFolder}\\1${targetFile}";
    }

  }


Last edited by WIntellect; 12-02-2002 at 05:11 PM..
# 11  
Old 12-03-2002
getting a error on line 2. says sumtin about predecement (--) on $trackFolder =


Weird ?
# 12  
Old 12-03-2002
Are you running it in Windows?

How are you starting the script?

Have you correctly altered the line:
$trackFolder = "c:\\perl_tmp";
?

Sounds very weird though!
# 13  
Old 12-03-2002
iam running in windows. The directory is correct. is there any other of doing it??
# 14  
Old 12-11-2002
I tried the script too and I got similar errors, as follows:
<B>
Can't modify predecrement (--) in predecrement (--) at rn.pl line 8, near "$trackFolder ="
Execution of rn.pl aborted due to compilation errors.</B>
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script for batch renaming

What is wrong with this script to rename batch of similar files? For example renaming all *.txt files to *.tab . $ for i in seq {01..10}; do touch ${i}.txt; done $ ./rename.sh *.txt txt tab Error: mv: ‘01.txt’ and ‘01.txt’ are the same file. Code is: #!/usr/bin/bash # renames.sh #... (6 Replies)
Discussion started by: yifangt
6 Replies

2. Shell Programming and Scripting

Cronjob script not renaming file

Hello, I have below script, which connects to ftp server, pull a file and then it renames it after deleting previous day file. This was working before but now it is not able to rename 'Red_bill.txt' to `Red_bill.V01.txt`. If I run manually 'rename Red_bill.txt Red_bill.V01.txt', I am able to... (5 Replies)
Discussion started by: solaris_1977
5 Replies

3. UNIX for Dummies Questions & Answers

Script for renaming multiple scripts

Hi There I am looking at writing a script that I can run from a cron job (say every month) that will copy my existing scripts to another folder, then in THAT new folder, append them all with the extension of .txt I have the cp command down pat (cp /existing_folder /new_folder) however I am... (6 Replies)
Discussion started by: orangepeel
6 Replies

4. Shell Programming and Scripting

Script help required in renaming

Given a directory containing 10 files: 1 - abcd1.txt 2 - abcd2.txt . . 10 - abcd3.txt 1 )Write a one liner sh script* to rename all files that start with a number less than 10, to have a zero in front. ie. 1 - abcd1.txt will be renamed to 01 - abcd1.txt. * You may not make use... (1 Reply)
Discussion started by: learnbash
1 Replies

5. Shell Programming and Scripting

Copying and Renaming script

Hey all! Sorry for the noobish question.. I am wondering how to I copy multiple files, and rename them based on their directory at once. So, I have files like this /logs/server/2011-10/server-1/log/file/folder/some.log.gz /logs/server/2011-10/server-2/log/file/folder/some.log.gz... (3 Replies)
Discussion started by: m3power206
3 Replies

6. Shell Programming and Scripting

Need script for renaming and moving files one by one...

Dears, I need your help! I got a problem and found some workaround solution but I donno how to realize it. I have a number of files (about 300 each day) and I need them to be renamed. All these files has fixed number of letters and name looks like this one:... (7 Replies)
Discussion started by: nypreH
7 Replies

7. Shell Programming and Scripting

Script for renaming files

I wanna back up the original version of files in a directory by appending .ORIG to them. I'm guessing I'd need CP and AWK in some form or fashion. Can someone give me a template? Thanks (3 Replies)
Discussion started by: stevenswj
3 Replies

8. Shell Programming and Scripting

script for renaming a batch of files

hi i have a folder full of files. some of the names are quite off because the dimensions were the same and i had to put a 'b' after the initial number so that it didnt overwrite. what i want is a script in unix to overwrite the filwe name leaving some of the title intact, e.g. below are some... (3 Replies)
Discussion started by: shabs1985
3 Replies

9. UNIX for Dummies Questions & Answers

Renaming Files using Shell Script

Hi Gurus, I have some files(all ending with .out as extension). Ex: aa1.out aa2.out aa3.out I would like to append each file with the current date to the end of the file so that they should become aa1_20090504.out. So I am using rename as follows: for i in path/aa* ; do mv $i... (5 Replies)
Discussion started by: asmfloyd
5 Replies

10. Shell Programming and Scripting

Renaming files in a bash script

I'm doing a short batch script to compile po files producing output binary mo files. The compilation command is: msgfmt -o file.mo file.po so in order to compile I am appending .mo to the varible in a loop. It goes something like this: for i in `find . -name "*.po"` do echo... (2 Replies)
Discussion started by: Breen
2 Replies
Login or Register to Ask a Question