Skip to main content
Inspiring
October 17, 2022
Question

function getfiles for file and not for folder

  • October 17, 2022
  • 1 reply
  • 777 views

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

This topic has been closed for replies.

1 reply

Community Expert
October 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

-Manan
Inspiring
October 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]);
			    }
Inspiring
October 18, 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


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)