Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

function getfiles for file and not for folder

Explorer ,
Oct 17, 2022 Oct 17, 2022

hi, i need to "relink" if files is deplaced OR name is changed

 

this code

		    if (internal_link[k].status == LinkStatus.LINK_MISSING){
			    var folderPath = (Folder.selectDialog(internal_link[k].filePath));
			    var imglist = Folder(folderPath).getFiles(internal_link[k].name+".*");
			    if (imglist.length == 1){
				internal_link[k].relink(imglist[0]);
			    }

 

open à dialog windows only for choose a folder and not select a new file for relink

 

 

thanks for you help

TOPICS
Scripting
939
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 17, 2022 Oct 17, 2022

Change Folder.selectDialog with File.openDialog

This will open a dialog box that will allow you to choose a file. However, I don't see a need for it as your code seems to be doing the right thing. It opens a dialog to select a folder and within that folder it tries to find a file with the name of the linked image and if found it relinks to the found image.

-Manan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 17, 2022 Oct 17, 2022

arf... i tested with file.selectdialog or file.selectdlg....

 

		    if (internal_link[k].status == LinkStatus.LINK_MISSING){
			    var folderPath = (File.openDialog(internal_link[k].filePath));
			    var imglist = Folder(folderPath).getFiles(internal_link[k].name+".*");
			    if (imglist.length == 1){
				internal_link[k].relink(imglist[0]);
			    }
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 17, 2022 Oct 17, 2022

As I said why do you want to select a file when what your code expects is indeed a folder to scan it. Secondly what happened when you used the openDialog menthod as you said. Did it work did it not?

-Manan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 17, 2022 Oct 17, 2022

Hi i have not test you method yet

 

For exemple my doc file name contain an error and i modify it

 

 

When I need to rethink, I need to select directly the good file and not the folder contain the old name file

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 17, 2022 Oct 17, 2022

Is English your native language, if not then probably try to write in your native language and lets see how the translation works. As I said your code expects a folder not a file then it does not matter if you select the correct file or not, it scans the folder. Also, I would suggest you to let one thing work and then move off to things like error handling etc.

-Manan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 17, 2022 Oct 17, 2022

i have test your function, and i have an error after the dialog box

 

thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 17, 2022 Oct 17, 2022

folderpath is different to internallink.filepath

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 17, 2022 Oct 17, 2022

@laurence roussel12011930 the problem is that you don't pay attention to what the other is saying. You asked to let you select a file using the dialog box. I gave you the function openDialog, using this you are selecting a file, and then you are trying to find files within a file. The line which is giving you an error means in your case to find files with a file(the one you selected from the dialog), does this make sense to you, no right?

So problem is not the code but the logic that you are trying to make. To me the simple logic would be your initial code, select the folder and search it for the file, if the file is found relink to it and you are done.

-Manan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Oct 17, 2022 Oct 17, 2022

I second @Manan Joshi on that one. You may need to take a step back, and think about what you are trying to achieve. Also questioning the source material. Scripting is just a handy way of solving issues once they have been clearly established. What about starting all over again with a clear description (no code) of your requirements?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 18, 2022 Oct 18, 2022

the missing link, mean 2 possibility

first file not appear into the file, because removed or cancelled

second name can be changed in this file or present in an other folder with a different name

 

the function 

 

	    if (internal_link[k].status == LinkStatus.LINK_MISSING){
			    var folderPath = (File.openDialog(internal_link[k].filePath));
			    var imglist = Folder(folderPath).getFiles(internal_link[k].name+".*");
			    if (imglist.length == 1){
				internal_link[k].relink(imglist[0]);
			    }

 

 

 

	    if (internal_link[k].status == LinkStatus.LINK_MISSING){
			    var filePath = (File.openDialog(internal_link[k].filePath));
			    var imglist = File(filePath).getFiles(internal_link[k].name+".*");
			    if (imglist.length == 1){
				internal_link[k].relink(imglist[0]);
			    }

 

 

i have try to modify it by that, but when i inspect the filepath before dlg box and after dlgbox

 

and filepath is different

 

one is c:\filepath

second is: desktop:\ filepath

 

if file is missing, i want just open dlgbox for select the new file for relink (maybe into other file or maybe with different name)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 19, 2022 Oct 19, 2022
LATEST

hi we have again the probleme on this code 

 

 internal_link = doc.links;

 

    if (nb_link > 0) {
        // doc.links.everyItem().update(); 
        // doc.save(); //idem
        for (var k = 0; k < nb_link; k++) {
            // internal_link = doc.links; 
            if (k > 0) {
                //internal_link[k].update();
            }
            // On vérifie que le lien est OK :
            if (internal_link[k].status == LinkStatus.LINK_MISSING){
			    var filePath = File.openDialog(internal_link[k].filePath);
				alert(internal_link[k].filePath)
				internal_link[k].relink(filePath.fsName);
				//internal_link[k].reinitLink(filePath.fsName);
		    }

 

 

 

we have try lot of thing, relink()  want file or String,

 

 

 

filePath.fsName is string (filpath is c:/..... and not String), fullname (desktop:/......)

my neighbourg problem come from [é] into my filepath name, but not sur

but impossible to find the solution

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines