Topic: Possible to use Siren inside files?

I need to rename a lot of AutoCAD drawings files(10,000+), but when I do this it will break the location for the project for each of the drawings. The directory and file names are stored in a simple text database file. I would like to be able to use the same expressions used in Siren to update the location of all those drawings inside the database file to their new location. Is there any way to do this with Siren? Thanks in advance for your help.

Tommy McClain

2 (edited by Stefan 2008-04-15 08:13:55)

Re: Possible to use Siren inside files?

Hi Tommy, welcome!

Please note that Siren is an tool to modify the names of files, not the content of files.

But you can export an tab separated list of current and future name:

* do your settings / modifying of the file names  (i think: don't rename right now)

* right click on an column header
* click "Customize..."
* for Columns choose "Future name" only
* [OK]
* Edit menu => Copy the selection => List with header
* open notepad and paste the clipboard with Ctrl+V
* save this as somename.txt  (delete the first line)

(do here your renaming)

* now use an script tool like www.AutohotKey.com to modify your "simple text database file" based on somename.txt

Autohotkey can parse somename.txt line by line
and take the part from line start till the TAB into an var
and then the second part from TAB till the end of line in another var

- then search the "first var" in your "database file" -
and replace this by the "second var"

HTH?

Remember: always test with copies of your real files.

Re: Possible to use Siren inside files?

Hello Tommy,

Stefan is right, Siren can only change file names but maybe the "Copy to clipboard" feature can help you.

All depends on the format of the text file you're talking about.
If it is only a simple list of file names:
- Start Siren, choose the directory
- If you want to list the subdirectories too, click on the "Recurse" button or press Ctrl+F5
- Select the files you want to list (Ctrl+A for all)
- Right click on the "Current name" column header
- Choose "Copy selected files data"
- Open a text file editor and paste the clipboard content

Depending on your needs maybe will you have to modify this file a bit.
If you're familiar with regular expressions a text editor supporting them could be very useful.

For a more complex list, ie if you want full path ... etc ...
- Create the needed rename expression
- Do the previous operations on the "Future name" column

I don't know "Autohotkey" but based on Stefan's expertise I am sure it can be extremely helpful.

Best regards

4 (edited by Stefan 2008-04-15 13:11:06)

Re: Possible to use Siren inside files?

OK, talking about editors featuring regex support:
Here are a few ones i can recommend,
like Siren they are Freeware/DonationWare , portable (no installation) and have a lot of features.

NotePad2   http://www.flos-freeware.ch/notepad2.html
PlainEdit   http://www.gaijin.at/dlplainedit.php  (German, but PlainEdit comes with english language too)
Notepad++     http://notepad-plus.sourceforge.net/
PSPad          http://www.pspad.com/


= = =   = = =   = = =   

Talking about AutohotKey
i have quickly searched an pseudo code for you, just to have an idea about:

(note: this is for CSV files, so simple search and replace TAB with , (COMA)  in somename.txt before)

Loop, read, somename.txt.csv,

   Loop, parse, A_LoopReadLine, CSV
  {
   CurrentField = %A_Index%
      if CurrentField = 1
        {
          Var1 = %A_LoopField%
        }
     if CurrentField = 2
      {
        Var2 = %A_LoopField%
      }

; here do an replacement
; StringReplace, OutputVar, InputVar, SearchText Var1 , ReplaceText Var2

  }

more support about AHK over at http://www.autohotkey.com/forum/

Re: Possible to use Siren inside files?

Excellent replies Remi and Stefan! Thanks so much! It's very helpful. Remi, you have an excellent program. It looks like it will do exactly what I need it to do. Provided I create the correct expressions. wink So far, I think I've got a handle on a few that I will need. Wish me luck.

There is only one issue I have with the copy to clipboard function. There's no full path of the directory for the Current Name column. My simple text database file includes the full path name of the file and since I'm going to be moving the file from one directory to another, I really need the Current Name to include the full path too. Now, I can get around this issue easily since the path for 90% of the files in my database file are exactly the same. All I have to do is paste that same path at the beginning of every line in the clipboard contents. However, with so many files it would be nice if they already had the full path from the start.

As for AutoHotKey, I looked at it briefly a couple of months ago when I was looking for a simple batch/scripting language. Since Stefan was so kind to provide me with a sample script I will definitely give it a try. Thanks Stefan! BTW, it's been a couple of years, but I used to write Perl scripts for a website I worked on. A lot of them would do parsing of HTML files or simple CSV files. But it's been so long that think I've forgotten how to do them. Oh well. I'm sure I can get AutoHotKey and your script to do a simple parse.

Tommy McClain

Re: Possible to use Siren inside files?

To copy the file names with the full path:
- Select the files as for a rename operation (Ctrl+A for all)
- Set the rename expression to: %fa
(filename with absolute path)
- Press Enter (or click the "recompute" button)

The "Future name"s are now what you were expecting (I hope so wink)

As I wrote in a previous post, right-click the "Future name" column header, choose "Copy selected files data", that's it.

If you need some advice for your rename expression, do not hesitate to post in this forum.

Re: Possible to use Siren inside files?

Remi, thanks again for the reply!

I already have the full path I need for the Future column. Here's an example expression I've already created for the destination files.

c:\Projects\\%b(5)\\%b.%e

But I need the Current Name column to include it's full path too. Right now it only shows the filename.

Tommy McClain

8 (edited by Stefan 2008-04-15 15:55:01)

Re: Possible to use Siren inside files?

Maybe
Expression:  %fa#delim#c:\Projects\\%b(5)\\%b.%e


to get an Future name something like:
C:\Temp\test HTML.html#delim#cProjects\ HTML\test HTML.html
C:\Temp\test.bm#delim#cProjects\\test.bm
(which shows that you have to take care with %b(5) expression for filenames with less then 5 chars.)


Then export Future name data to clipboard
- paste in editor
---- search for "#delim#c\"
- replace with "#delim#c:\"


Then set Expression back to "c:\Projects\\%b(5)\\%b.%e"

Just BTW (i hope this was no nonsense) ... back to work

Re: Possible to use Siren inside files?

Thanks again Stefan! That works just fine. I will just have to delete or ignore the first field/column when I start parsing it. I'll leave you alone now. I'll probably post again once I've completed the whole process. Wish me luck!

Tommy McClain

Re: Possible to use Siren inside files?

Good luck!

And come back and tell us the whole solution story for sure ;-)




Thanks for your feedback!

Re: Possible to use Siren inside files?

OK, I thought I had the right expression, but I'm starting to realize that since my directory has all kinds of files in it, I havning problems filtering only the ones I need to rename. All the files I want to rename should be in the format: ????####.* Where ?=character(could be 0-4 characters), #=number and *=character(could be any number of characters). We tried to stick to a 8.3 DOS format for all files. Unfortunately we exceeded 9999 and went to naming files using ???#####.* I pretty much figured I needed to take care of the 5-digit filenames first, and then work on the files that had 4 digits. But I was hoping maybe somebody could give me another suggestion. Here's what I have so far...

4-digit files...
z:\Projects\\%bd(-4)\\%b.%e

5-digit files...
z:\Projects\\%bd(-5)\\%b.%e

I was hoping there was some kind of expression for including only files that the last 4 characters of the 8-character filename were numbers (ex: 0000-9999).

I've checked the directory and there are about 31,000 files in this one directory. About 3100 files are 5-digit filenames (ex. 10000-10999). The files haven't got into 11000, but they will soon.

Any help you can provide would be greatly appreciated. Thanks!

Tommy McClain

Re: Possible to use Siren inside files?

FYI, the reason I'm keying on those 4-5 digits is because those are job numbers. About a year ago we hit job #10000. I'm not actually renaming the actual files, just moving all the files associated with a job number to their own subdirectory named by their job jumber.

Tommy McClain

Re: Possible to use Siren inside files?

OK, now I feel a little dumb. Found a more useful expression...

z:\Projects\\%N\\%b.%e

It doesn't get all of the files, but comes close. I still have de-select a few stragglers, but it should work better for one of my directories. Unfortunately, I have another directory where all 8 characters are numbers. So just picking the last 4 digits won't get the jobs that have a 10000+ job job number. If I pick the last 5 digits, then the 4-digit job numbers won't get placed right. I will probably have to do 2 different expressions for those files. One to get the 10xxx files and another to get the xxxx files. Oh well. Can't win them all. smile

Tommy McClain

Re: Possible to use Siren inside files?

OK, some more thinking... smile If I could check the 5th character from the left of a 8-character DOS filename and if it's a 0(zero), then grab 5 digits from the right to get the job number. If that 5th character is a number 1-9, then grab 4 digits from the the right to get the job number. Is this possible with RegEx? Thanks!

Tommy McClain

Re: Possible to use Siren inside files?

Hi, i can't follow you right now. To early in the morning. But...
...here are some thought, don't know if this help you or if that works in Siren.


> I havning problems filtering only the ones I need to rename.
Siren have an Filter to show only matching files. Maybe this helps?
From the help "In the "Filter" combo, you can enter a string to limit the file  list (for example: *.mp3)."


> If that 5th character (from the right) is a number 1-9, then grab 4 digits from the the right .... Is this possible with RegEx?
Siren use the RegEx engine of boost which should provide "Lookaround"
I have no time, but you could search for "positive, negative, lookbehind, or lookahaed"
or here is an link http://www.regular-expressions.info/lookaround.html
Something like: (?<=\d)\d\d\d\d

.

Re: Possible to use Siren inside files?

Ah, @ Rémi:
the boost links in the help like http://boost.org/libs/regex/doc
are not longer valid, just FYI

Re: Possible to use Siren inside files?

Hello,

To select your files you can use a filter.
Let me give here some explanation.
In Siren the file filters can be used in different places. The most obvious is the "Filter" combobox in the main window. During a directory (tree) scanning only the files passing the filter are taken into account.
You may have noticed that for the selections, highlights ... a filter can also be used.

For example, if you want to automatically select (checkboxes checked) only the "mp3" files, press Ctrl+S (or menu option Select/Select with a filter), enter "*.mp3" (without the ") and click OK.

But that's not all. The filter schema in Siren is not only the standard DOS one. I've extended it to the unix shell one. The help contains a very small description of this. I think it is adapted to your problem.

You surely already know the DOS '?' and '*' characters symbolizing any character (?) or any string (*)
In Siren this list has been extended with: [-]!
This allows you to specify specific character sets or intervals.

For example, if you want only the mp3 files beginning with 'A' or 'B'.
The corresponding filter can be: [AB]*.mp3
For the mp3 files beginning with 'A' to 'Z' it can be: [A-Z]*.mp3
If you don't want mp3 files beginning with 'A' through 'Z', it can be: [!A-Z]*.mp3

Note that I've not invented this, it is part of the standard unix shell.
It has nothing to do with regular expressions.

Let's come back to your problem:
To select/filter ... only the files with base names ending with at least 4 digits, you can use a filter like:
*[0-9][0-9][0-9][0-9].*

Of course you can use ';' (semicolon) to concatenate different filters: *.mp3;*.txt

I hope that this text will help.