Finding file within directory

I'm currently using InDesign CS5.5
I have an automation script I wrote for datamerge in javascript but I've had trouble finding any references to searching for files with javascript. I'm well aware you can't in javascript for the web but there is server side scripting but can't find where any tutorials are online.
What im trying to acheive is this line here... but in javascript.
var rootName = app.doScript('set theFile to (do shell script "ls /Path/To/Folder")', ScriptLanguage.APPLESCRIPT_LANGUAGE);
now to explain why im using this incase anyone wants this or wants to know... this will give me a list of filenames in a directory..
I then apply..
var filename = rootName.split('.').reverse().slice(1).reverse().join('.');
which strips everything but the name of  the file without the extension.
Part of my program is.. each csv file that comes in will not have the same name so I use this to get the name and then later apply it to my datasource and for saving out the PDF.
I'd appreciate if anyone can help me acheive looking for a file within javascript or if they could send me a link to where some documentation is.
I have tried using getFiles("*.csv") but I get errors.. when I slap an alert after getting the file it shows the file with the entire path and I can't use slice because it doesn't do anything. literally it doesn't slice. This is why I was using applescript. I'm not sure if its more efficient or not to use Javascript for this or Applescript just would like to keep it all one language.
Eventually I'd like to figure out how to set up a for function or some sort of count to grab only 1 file at a time in the case that 2 files make it to the directory.
Also if anyone wants the code to do a datamerge and save out to pdf I'll gladly post.
Thanks

jtcdesigns1 wrote:
I'm better at modifying than creating
Modify this to taste
filename = fetch_me_a_file ("*.csv");
if (filename == null)
alert ("No file found, or user canceled");
else
alert (filename);
function fetch_me_a_file (mask)
var fileList = Folder.myDocuments.getFiles(mask);
if (fileList.length == 0)
  alert ("No files found");
  return null;
if (fileList.length == 1)
  return fileList[0].name;
var selectedFile = Folder.myDocuments.openDlg("Fetch me a file", mask);
// Canceled?
if (selectedFile == null)
  return null;
return selectedFile.name;
I was wondering if and how your Split Off Filename line worked, but decided to use this RegExp instead:
name = filename.replace(/^.+\//, '');
(replacing everything before and including the final forward slash with nothing) but then I thought, wait a minute. The 'object' returned by both getFiles and by openDlg is not actually a file name -- even though JS conveniently translates it to a fully qualified path when asked --, it's a file object. And a regular File object has this useful property 'name': that's just the file name.

Similar Messages

  • Find File in directory

    Is it possible to find in a given folder (folder project) for files by mask?

    var folderObj = new Folder (folderName);
    if (folderObj){
          var files = folderObj.getFiles();
          for (var i = 0; i < files.length; i++){
              var name = files[i].displayName;
              if (name.indexOf(".txt") != -1){ ........ } //if file name contains ".txt", then .....
              //если имя файла содержит ".txt" то условие будет выполнятся

  • Batch code for running a find/replace all on multiple files within a source floder/directory

    What I need is a Batch source code that will open all files in a folder/directory and run a find and replace_all query within them and then save all the files.  The files were created in Illustrator and saved using the Scene7 FXG format extension.    These files will be uploaded into Scene7 as a group after the find and replace macro/query is run on the code.  The same find and replace query will be the same for all the files.  Basically this function or batch process  will save time in setting the same parameters all at one time instead of having to set the parameters individually in scene7.
    a source code sample of the find/replace module macro might be              searchString:  s7:colorvalue="#FFFFFFFF" 
                                                                                                                          replaceString: s7:colorValue="#&txtclr;"
                                                                                                                          searchWhat   "FXG document"    
                                                                                                                             searchSource:  true,
                                                                                                                        useRegularExpressions:   true
    I have no problems creating batch files within Ai and PhotoShop but I have limited programming skills in how to create source code for manuipulating documents outside of those apps or in a OS invironment.
    I could probably come up witha simple program to do what i want for one document but i get lost when dealing with multiple documents in a source folder (prolbem is,  I will be dealing with thousands of documents not 100 or less)
    If anything which Adope cloud app would work best:  Dreamweaver or Edge code   (or just use my notepad)

    What I need is a Batch source code that will open all files in a folder/directory and run a find and replace_all query within them and then save all the files.  The files were created in Illustrator and saved using the Scene7 FXG format extension.    These files will be uploaded into Scene7 as a group after the find and replace macro/query is run on the code.  The same find and replace query will be the same for all the files.  Basically this function or batch process  will save time in setting the same parameters all at one time instead of having to set the parameters individually in scene7.
    a source code sample of the find/replace module macro might be              searchString:  s7:colorvalue="#FFFFFFFF" 
                                                                                                                          replaceString: s7:colorValue="#&txtclr;"
                                                                                                                          searchWhat   "FXG document"    
                                                                                                                             searchSource:  true,
                                                                                                                        useRegularExpressions:   true
    I have no problems creating batch files within Ai and PhotoShop but I have limited programming skills in how to create source code for manuipulating documents outside of those apps or in a OS invironment.
    I could probably come up witha simple program to do what i want for one document but i get lost when dealing with multiple documents in a source folder (prolbem is,  I will be dealing with thousands of documents not 100 or less)
    If anything which Adope cloud app would work best:  Dreamweaver or Edge code   (or just use my notepad)

  • File browse functionality for all files within a directory

    I have an app where you use file browse to select a file on the file system. Then, I parse the file name to determine other attribution to record in database, which may result in more user interaction before creating the database record.
    So, currently users can do this one file at a time. Anything available to let me loop through all files within a user-specified directory?
    Thanks,
    Steve

    I have an app where you use file browse to select a file on the file system. Then, I parse the file name to determine other attribution to record in database, which may result in more user interaction before creating the database record.
    So, currently users can do this one file at a time. Anything available to let me loop through all files within a user-specified directory?
    Thanks,
    Steve

  • How to find files and subdirectories in a directory

    can anyone tell me how to find files and subdirectories in a directory .

    Here's a code snippet,
    http://javaalmanac.com/egs/java.io/TraverseTree.html

  • Cp: com.apple.finder.plist: No such file or directory

    Hello,
    As the title suggest, I'm having a problem with cp.
    As the matter of fact, com.apple.finder.plist is inside the preferences folder but why "No such file or directory"?
    The-Universe:~ LS$ cp com.apple.finder.plist com.apple.dock.plist.bak
    cp: com.apple.finder.plist: No such file or directory
    I learnt this command-line form the "Mac OS X Server Introduction to Command-Line Administration Version 10.6 Snow Leopard", pg 38.
    Thanks!
    Cheers.

    I would suggest having a backup of your whole disk, and particularly of any critical files, before proceeding here.
    The the documentation is assuming that you're defaulted into the expected directory, and the path to the plist directory is discussed in the immediately previous section of the manual you're working with. If you're logged into the user you want to edit, the plist files are here: ~/Library/Preferences/
    So some of the bash-level commands that can be used here (and that you will want to understand) follow:
    ls ~/Library/Preferences/
    ls -alR ~/Library/Preferences/
    cd ~/Library/Preferences/
    ls
    ls com.apple.finder.plist
    cp com.apple.finder.plist com.apple.dock.plist.bak
    The specific error here appears to be that the default directory is not in the expected directory. That's what cp has indicated; that there's no file with the specified filename here. The current directory is what the pwd and cd commands will work with, too. See +man pwd+ and +man cd+ for details.
    The Unix layer is comparatively unforgiving, and it's easy to corrupt a disk with an errant command. And the manual you're reading isn't going to explain what are the basics of the Unix file system organization and the bash shell; that's assumed knowledge for that manual, and outside the scope of what that manual is going to be documenting. Do have a backup of your disk, and of your critical data.

  • Find: stat() error /proc/26354: No such file or directory

    Dear everyone,
    I am using Solaris 10u8 on 02 Sun Fire X4240 servers. I also installed Sun Cluster 3.2u3 and Oracle RAC 10gR2 for these 2 servers.
    When I tried to execute the find command, I receive the result I need. However, in the end of the output, I saw additional lines:
    +# find / -name * log -print | grep samba+
    +/var/svc/log/network-samba:default.log+
    +/var/samba/log+
    +/etc/svc/volatile/network-samba:default.log+
    +{color:#ff0000}find: stat() error /proc/26354: No such file or directory{color}+
    I also tried with less complex syntax but got the same result, for example:
    +# find / -name samba+
    +/var/spool/samba+
    +/var/samba+
    +/usr/sfw/lib/webmin/caldera/samba+
    +/usr/sfw/lib/webmin/mscstyle3/samba+
    +/usr/sfw/lib/webmin/samba+
    +/etc/init.d/samba+
    +/etc/webmin/samba+
    +/opt/SUNWscsmb/samba+
    +{color:#ff0000}find: stat() error /proc/24252: No such file or directory+
    +find: stat() error /proc/24345: No such file or directory{color}+
    I don't know why these unormal outputs appeared. Does anyone know what the problem is here ?
    Any advice from you is appreciated. Thanks for your help and please help me in this case.
    Thanks.
    HuyNQ.

    /proc is a virtual filesystem reperesenting running processes.
    By doing a a find from / your allowing find to pass though /proc.
    Those errors indicate processes that exited while the find was running. So the files suddenly disappeared.
    The errors are harmless. But if possible, try not to allow find to scan /proc.

  • Cannot find real path for '/var/install/Client/DATA_UNITS/HDB_CLIENT_LINUX_X86_64/../install/sdbrun': No such file or directory

    Hi Experts,
    I got the error "cannot find real path for '/var/install/Client/DATA_UNITS/HDB_CLIENT_LINUX_X86_64/../install/sdbrun': No such file or directory" and "Error during execution of HdbCmdClazz section!" during SAP NW 740 HANA installation. I specified the right path for HDB client (see in attachment).
    Any ideas, please?
    Thanks & best regards,
    Sreenu

    The service file is in $srcdir, not $_svnmod/builders/cmake.
    You're using an outdated PKGBUILD template too. The svn source should be included in the source array and not checked out manually during the build process.
    EDIT: since this repository requires authentication, perhaps the correct format won't work.
    Last edited by WorMzy (2015-02-08 23:07:59)

  • Why does the Yosemite Finder become unresponsive when moving a file within my USB Flash stick?

    Why does the Yosemite Finder become unresponsive when moving a file within my USB Flash stick? I have to Relaunch the Finder to get it working again.
    Background / other symptoms:
    The Flash drive in question has been formatted HFS.
    I get no error messages, including on the Console, and no sound indicators.
    I can copy files, using the Finder, from a hard-drive to the usb flash drive with no problem.
    Finder copying on this stick works just fine on my other Mac.
    I can move files within another (FAT32-formatted) USB flash drive.
    The quirky USB HFS Flash drive works fine on my other Mac.
    Outside of the Finder, I can use mv just fine to move the files on the HFS flash drive.
    If the HFS-formatted Flash drive were faulty, I would at least expect some sort of error in the Console app, but perhaps not from the Finder.

    Why does the Yosemite Finder become unresponsive when moving a file within my USB Flash stick? I have to Relaunch the Finder to get it working again.
    Background / other symptoms:
    The Flash drive in question has been formatted HFS.
    I get no error messages, including on the Console, and no sound indicators.
    I can copy files, using the Finder, from a hard-drive to the usb flash drive with no problem.
    Finder copying on this stick works just fine on my other Mac.
    I can move files within another (FAT32-formatted) USB flash drive.
    The quirky USB HFS Flash drive works fine on my other Mac.
    Outside of the Finder, I can use mv just fine to move the files on the HFS flash drive.
    If the HFS-formatted Flash drive were faulty, I would at least expect some sort of error in the Console app, but perhaps not from the Finder.

  • Could not find file in Temp directory

    Hey all!
    I received the follwoing error when exporting a report into a pdf file using the ExportToStream method:
    Could not find file "C:\DOCUME1\CHL0337\ASPNET\LOCALS1\Temp\export_e269c3d0-e775-4351-b2ea-09507859a79a.tmp".
    I am using VS 2003 and CR 9.1.5, and I didn't have any problems with this report until I enlarged the header field for a column. After this error occurred, I reverted back to the original report, but it still threw the error. I then restarted IIS, rebuilt the application, and then ran the report again. Still no luck.
    Any ideas on what is causing this problem? Is this a version issue?
    (I have four other reports that are still working fine, it just seems to be this one report)

    Here is the full dump of the error message:
    Exception=System.IO.FileNotFoundException
    Message=Could not find file "C:\DOCUME1\CHL0337\ASPNET\LOCALS1\Temp\export_d03e5522-a635-47c0-b649-a238063b0223.tmp".
    FileName=C:\DOCUME1\CHL0337\ASPNET\LOCALS1\Temp\export_d03e5522-a635-47c0-b649-a238063b0223.tmp
    TargetSite=Void WinIOError(Int32, System.String)
    StackTrace= at System.IO.__Error.WinIOError(Int32 errorCode, String str)
    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy)
    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
    at CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext)
    at CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToStream(ExportFormatType formatType)
    at FixedAssets.FAPageBase.InvokeCrystalReport(String ReportName) in c:\dev\source\comptrollers\fixedassets\dev\web\fapagebase.aspx.cs:line 588
    at FixedAssets.Reports.CreateAssetDisposalsReport.btnRunReport_Click(Object sender, EventArgs e) in C:\dev\source\comptrollers\FixedAssets\Dev\web\Reports\AssetDisposalsReport.aspx.cs:line 70
    at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
    at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
    at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
    at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
    at System.Web.UI.Page.ProcessRequestMain()
    Source=mscorlib

  • Okay, i have 2 bugs with maverick.  First, when I delete a file within a window, the files deletes but the preview doesn't delete until I close the window and reopen it.  Second, I work on a network of computers and the search feature is now buggy...

    Okay, i have 2 bugs with maverick.  First, when I delete a file within a window, the files deletes but the preview doesn't delete until I close the window and reopen it.  Second, I work on a network of computers and the search feature is now buggy...  When I search for a file, A) it asks me if it's a name, or it wont produce anything, and B), its slower than in prior OS versions and in some instances I have to toggle to a different directory and go back to my original directory in the search: menu bar or the search wont produce anything...  Very buggy. 

    It appears to me that network file access is buggy in Maverick.
    In my case I have a USB Drive attached to airport extreme (new model) and when I open folders on that drive they all appear empty. If I right click and I select get info after a few minutes! I get a list of the content.
    It makes impossible navigate a directory tree.
    File access has been trashed in Maverick.
    They have improved (read broken) Finder. I need to manage a way to downgrade to Lion again.

  • Smart Folders to find files with certain priviledges

    How do I set up a smart folder to display files that have only read&write privileges within a directory.

    You mmight have better success using a standard Finder search. In the Finder press Command-F and then you can apply various filters to isolate files based on kind, name, dates created/modified, and a large number of additional metadata criteria.
    If for some reason you can only find files that you have already modified (ie, by searching wiith modification date), then one way to reverse this for a search is to first find these files, then select them all and apply a Finder label to them (ie, "Red") and then perform the search on the same folders again but this time search for all items that are not labeled "Red" and your other items should show up.

  • Getting "file://" to finder files

    At work, we've got a bunch of Mac's networked. I use iChat to send the location of files on the network. What I would love is to be able to send the path to the file in link format, have someone click on it, and then have that linked directory open in the Finder.
    I first accomplished this by opening a file within Safari, getting the "file://" path, and cut and pasting that into iChat. So I know it works.
    I have two questions...
    First, what is the "file://" path structure called?
    Second, is there a way to automatically acquire a file's path within the Finder, with "file://" already prepended? Or do I need to type it in manually each time?
    chris

    Try it with three slashes:
    *file:///"path to item"*
    BTW, AFAICT, it will open the file in the appropriate app, but not its location.
    For example,
    *file:///Applications/Safari.app/Contents/Resources/English.lproj/Plug-ins.html*
    Opens the installed plug-ins page in Safari.

  • How to create a Dir and files within it?

    Hi all ,
    I need to create a Dir and some sample files within it for some testing purpose,can any body tell me how to do it?(I follow al11 GUI options but its giving some error)
    Or
    Is there any FM by which we can do it directly to application server????
    Its urgent requirement..
    Thanx in advance

    to create a file in appl server you have to use open dataset and close data set..
    see the sample code
    REPORT zanid_test MESSAGE-ID zz .
    parameters:  FULLPATH(128) obligatory lower case
                          default 'E:\usr\sap\put\file.txt'.
    *you change the appl sever path as per your config.
    DATA : BEGIN OF list_asc OCCURS 0,
            msg(300) TYPE c,
           END OF list_asc.
    start-of-selection.
    *---populating data
    list_asc-msg = 'abcdefghijkl'. "your sample data
    append list_asc.
    list_asc-msg = 'faagoaagiagig'. "your sample data
    append list_asc.
    OPEN DATASET fullpath FOR OUTPUT IN TEXT MODE.
    LOOP AT LIST_ASC.
          TRANSFER  LIST_ASC-MSG TO fullpath.
          CLEAR LIST_ASC-MSG.
    ENDLOOP.
    CLOSE DATASET fullpath.
    now if you go to appl server , you will find that file in that specified path..
    to create a directory yu can go to transaction AL11 and click the 'konfigurieren'button, you then you can specify the directory attibutes to create a directory
    and to load a file from your loacl pc to appl server you can use transaction CG3Y also, instead of the abap code.
    plz rewrad points if it helps you.

  • Find files that match with given string, except one character in a fixed position

    Hi,
    I want to find files in a directory with a given string (ss-20140129-process-000*.sdx), where only one character will be mismatched, so have to use wildcard for that character. This means I am looking for filenames where everything needs to be matched except
    one character in position of "*". For the samples given below: 1st 3 files matched with the given string, but last 3 files have not matched, so first 3 files will be counted.
    ss-20140129-process-0001.sdx
    ss-20140129-process-0004.sdx
    ss-20140129-process-0009.sdx
    zx-20140129-process-0001.sdx
    bt-20140129-process-0002.sdx
    zx-20140129-process-0001.sdx
    I can use the command like (GCI -path $folder -filter ss-20140129-process-000?.sdx), BUT problem is i am building a string for the filter (code given below), where i DO NOT know how to use "?" within the string to make a character exception.
    Code:
    $datevalue = [datetime]::parseexact($trandate,"MMddyy",$null)
    $yyyymmdd = $datevalue.tostring('yyyyMMdd')
    $FileToCheck = ("ss-"+$yyyymmdd+"-process-000?.sdx")
    GCI -path $folder -filter $FileToCheck
    But it's definitely NOT working for syntax problem.
    Any help?

    I don't think it's a syntax issue in the filter.  This works fine for me:
    $yyyymmdd = '20140129'
    $FileToCheck = ("ss-"+$yyyymmdd+"-process-000?.sdx")
    Get-ChildItem -Path . -Filter $FileToCheck
    <#
    Output:
    Directory: C:\source\Temp\sdxtext
    Mode LastWriteTime Length Name
    -a--- 1/30/2014 10:16 AM 0 ss-20140129-process-0001.sdx
    -a--- 1/30/2014 10:16 AM 0 ss-20140129-process-0004.sdx
    -a--- 1/30/2014 10:16 AM 0 ss-20140129-process-0009.sdx
    #>
    You can try adding some debug output right before the call to Get-ChildItem. Check the values of $Folder and $FileToCheck, make sure they're correct. You can also fiddle with the values and call Get-ChildItem manually until it works, which would then tell you
    how the code needs to be changed.

Maybe you are looking for