Need spome help please :)

Hello :slight_smile:

SO here is my problem.
I have this code and need it to work but i cant do it by myself and now
need to ask you if you can help.

Changing the file name

def file_rename(path)
    case path

        when $file_pos_path         then $file_name.value = "zdjęcie

stanowiska POS w PSD" and file_ext = $file_pos_ext and old_file =
$file_pos_path
when $file_kableprzed_path then $file_name.value = “stan
okablowania POS w PSD” and file_ext = $file_kableprzed_ext and old_file
= $file_kableprzed_path
when $file_kablepo_path then $file_name.value =
“zdjęcie stanowiska POS w PSD” and file_ext = $file_kablepo_ext and
old_file = $file_kablepo_path
when $file_posprzed_path then $file_name.value = “stan
POS w PSD” and file_ext = $file_posprzed_ext and old_file =
$file_posprzed_path

    end



    if path != nil or "#{path}".length != 0 then
        File.rename("#{old_file}", "Ruch, #{$file_name} #{$psd},

#{$miejscowosc}#{file_ext}")

I would like for this script to only change name of first one like that
but for those last three so it will change it like this:

        File.rename("#{old_file}", "Ruch, #{$file_name} #{$psd}

przed migracjÄ…, #{$miejscowosc}#{file_ext}")

Any chance for someone to write it for me in proper way?

Thanks in advance

its a shame that theres noone here who could help

marcin k. wrote in post #1030356:

its a shame that theres noone here who could help

hi Marcin,

it is not at all clear what the variables ($file_name, $file_pos_path,
old_file, $psd, $miejscowosc, etc.) that you use refer to. the method
value which is called is not defined. a method file_rename which
takes one argument is defined but never called, and later a rename
method which takes 3 arguments is called but never defined. def,
case, and if are all called, yet there is only one end. this is
not executable code and that makes it next to impossible to comment
on…

Any chance for someone to write it for me in proper way?

i doubt that anyone here is willing to write it for you, and i imagine
that’s not what you really want either (what fun would that be?!) i’m
sure there are plenty of people reading the forum who would be happy to
help you, but you’ve got to give folks something to work with :slight_smile:

  • j

well its only pice of the code … everything is called before or after.

The problem is

i have 12 photos and i want to be able to select them in browse window
and than i want program to rename it according to specific rules where
we have 2 changables and are difined by user everytime when the
application starts

where 1st one is PSD number and second it cityname

so on exit first 9 photos should looks like this

xxx,xxxxxxxxxxxxxxx xxxxxxxxxxxx PSD ,

and last 3 photosh should looks like this

xxx, xxxxxxxxxxxxxx xxxxxxxxxxx PSD po migracji ,

hi Marcin,

i often find that trying to work from within something so large gets
confusing and distracting - a good idea might be to begin by reducing
what you want to do down to the bare minimum. try to write a simple
method that renames files based on parameters that you pass to the
method, and then incorporate that into your larger code.

  • j

On Sun, Nov 6, 2011 at 9:09 AM, marcin k. [email protected]
wrote:

so first 9 photos should looks like this

xxx,xxxxxxxxxxxxxxx xxxxxxxxxxxx PSD ,

and last 3 photosh should looks like this

xxx, xxxxxxxxxxxxxx xxxxxxxxxxx PSD po migracji ,

I am not sure I understand what you are trying to achieve. I do
notice though a highly repetitive structure of your code which means
you should be able to refactor a lot of this into much smaller code
base with clearer structure. For example, you have sets of global
variables (generally a bad idea btw.) which follow common naming
conventions and are treated similarly. In that case it’s better to
have collections (either Hash or Array) store the stuff and manipulate
it there. The code might also benefit from some class definitions of
your own.

Also not everybody here is able to read Polish. So it would be easier
for us to help if you change the commenting and variable and method
naming to English.

Kind regards

robert