Skocz do zawartości

Rekomendowane odpowiedzi

Opublikowano

Cześć wszystkim mam bardzo mały problem a myślę że większość tu ludzi zna odpowiedź tak więc nie wiem jak zdobyć nazwę pliku który wybieram używając kodu

 

GML
wtyczka = get_open_filename("Wtyczka AldStream Biblioteka DLL ( *.dll )|*.dll","")

if wtyczka != '' {global.wtyczka = wtyczka} else {exit}

 

chodzi o to że global.wtyczka musi pobrać nazwę pliku z tego całego wiersza a nie z jakiego jest miejsca ten plik. Da się tak? Pozdrawiam

Opublikowano
Czyli co?

 

Chodzi o to że: piszesz takie coś:

 

GML
var a;

a=get_open_filename("*.png|*.png","")

show_message(a)

 

i wybierasz sobie jakiś plik graficzny np Biblioteka/Obrazy no i w show_message pojawia się tekst z miejscem docelowym tego zdjęcia:

 

GML
C:\Users\Paffcio\Pictures\jakies_zdjecie.png

 

a ja chce do zmiennej wpisać nie C:\Users\Paffcio\Pictures\jakies_zdjecie.png ale jakieś_zdjecie.png

I czy da sie ominąć tę niepotrzebną lokalizacje C:\User....

Opublikowano

Utnij se.

https://gmclan.org/index.php?wiki=article&zm=32

 

 

Mniej więcej to wygląda tak:

GML
global.wtyczka="C:\Users\Paffcio\Pictures\jakies_zdjecie.png";

 

var len, last_char;

len=string_length(global.wtyczka);

last_char=-1;

 

for(i=0; i < len; i+=1) if (string_char_at(global.wtyczka, i) == '\') last_char=i; //wyszukiwanie ostatniego ukośnika

global.wtyczka = string_delete(global.wtyczka, 0, last_char + 1);

Nie sprawdzałem czy działa.

Opublikowano
GMLglobal.wtyczka="C:\Users\Paffcio\Pictures\jakies_zdjecie.png";

 

var len, last_char;

len=string_length(global.wtyczka);

last_char=-1;

 

for(i=0; i < len; i+=1) if (string_char_at(global.wtyczka, i) == '\') last_char=i; //wyszukiwanie ostatniego ukośnika

 

global.wtyczka = string_delete(global.wtyczka, 0, last_char + 1);

 

Plik kopiuje się bez błedów jak sobie tam ustawiłem ale miejsce końcowe to plik "-1" bez rozszerzenia. To właśnie wychodzi z last_char tylko za bardzo nie mogę rozczytać w czym tu problem eh, wiesz może w jakiej zmiennej jest ta nazwa?

Opublikowano

Dobra, sprawdziłem u siebie.

Stwórz sobie skrypt o nazwie get_file_from_path.

GML
//SKRYPT get_file_from_path

//wyodrębnia nazwę pliku z pełnej ścieżki

//argument0 - ścieżka

var len, last_char;

len=string_length(argument0);

last_char=-1;

 

for(i=0; i < len; i+=1) if (string_char_at(argument0, i) == '\') last_char=i; //wyszukiwanie ostatniego ukośnika

return string_copy(argument0, last_char + 1, len);

 

i użycie dla twojego przypadku:

 

GML
wtyczka = get_open_filename("Wtyczka AldStream Biblioteka DLL ( *.dll )|*.dll","")

if wtyczka != '' { global.wtyczka = get_file_from_path(wtyczka); } else {exit}

Opublikowano
The following functions can be used to change file names. Note that these functions do not work on the actual files they only deal with the strings.

 

filename_name(fname) Returns the name part of the indicated file name, with the extension but without the path.

filename_path(fname) Returns the path part of the indicated file name, including the final backslash.

filename_dir(fname) Returns the directory part of the indicated file name, which normally is the same as the path except for the final backslash.

filename_drive(fname) Returns the drive information of the filename.

filename_ext(fname) Returns the extension part of the indicated file name, including the leading dot.

filename_change_ext(fname,newext) Returns the indicated file name, with the extension (including the dot) changed to the new extension. By using an empty string as the new extension you can remove the extension.

 

GML
wtyczka = get_open_filename("Wtyczka AldStream Biblioteka DLL ( *.dll )|*.dll","")

if wtyczka != '' {global.wtyczka = filename_name(wtyczka)} else {exit}

Opublikowano
The following functions can be used to change file names. Note that these functions do not work on the actual files they only deal with the strings.

 

filename_name(fname) Returns the name part of the indicated file name, with the extension but without the path.

filename_path(fname) Returns the path part of the indicated file name, including the final backslash.

filename_dir(fname) Returns the directory part of the indicated file name, which normally is the same as the path except for the final backslash.

filename_drive(fname) Returns the drive information of the filename.

filename_ext(fname) Returns the extension part of the indicated file name, including the leading dot.

filename_change_ext(fname,newext) Returns the indicated file name, with the extension (including the dot) changed to the new extension. By using an empty string as the new extension you can remove the extension.

 

Dziękuje tobie za chęci, i bardzo to doceniam :) Jak będe miał chwile czasu to na spokojnie to przeczytam. Puki co dzięki!

 

PS: Proszę admina o zamknięcie tematu.

Opublikowano

Konkretnie to Huderowi chodziło o funkcję:

GML
filename_name(fname) Returns the name part of the indicated file name, with the extension but without the path.

Nie siedzę w GM to nie kojarzę większości funkcji ;p

Jeśli chcesz dodać odpowiedź, zaloguj się lub zarejestruj nowe konto

Jedynie zarejestrowani użytkownicy mogą komentować zawartość tej strony.

Zarejestruj nowe konto

Załóż nowe konto. To bardzo proste!

Zarejestruj się

Zaloguj się

Posiadasz już konto? Zaloguj się poniżej.

Zaloguj się
  • Ostatnio przeglądający   0 użytkowników

    • Brak zarejestrowanych użytkowników przeglądających tę stronę.
×
×
  • Dodaj nową pozycję...