AppleScript to delete a text file

Hi, here is a job Applescript that lists the contents of a folder and its subfolders to a text file named 'file inventory. The problem, for example, is that if a subfolder is emptied of files, the list of his previous content is always indicated in the text of the inventory of the last time file that the script is run. So, I would delete all of the text in the file until it is written again. I searched and found this code and put my name of file in there, but I can't make it work.

Any help will be appreciated.

expressions of folklore ": folder files inventory.txt" value 0

property file_id: null


              tell application "Finder" for the value this_folder for folder 'movies' from disk 'files '.

the value log_file_path to ": folder files Inventory.txt.

file_id value to open access file log_file_path with write permission

Try

write ('Start' & (current date) & back) to file_id

my do_subfolders (this_folder, "")

write (back & return) to file_id

file_id of close access

say "finished".

we error error message

file_id of close access

errMsg say

              end try

on do_subfolders (this_folder, name_prefix)

say application 'Finder '.

Journal name_prefix & string (name of this_folder)

write (back & name_prefix & (name of this_folder) chain ) to file_id

the value File_List for each file in this_folder

Repeat with this_file in File_List

Journal name_prefix & "" & string (name of this_file)

write (back & name_prefix & "" & (name of this_file) chain ) to file_id

end Repeat

the value folder_list for each folder in this_folder

Repeat with this_subfolder in folder_list

my do_subfolders (this_subfolder, "" & name_prefix)

end Repeat

end say

end do_subfolders

You are on the right track, but set the folklore expressions takes the file reference that you have already opened, not the path text.

so, since you open the file via:

file_id value to open access file log_file_path with write permission

the appropriate solution would be:

file_id of the folklore of the value to 0

Tags: Mac OS & System Software

Similar Questions

  • How to erase a text file...

    Hi all...

    I wud would like to know how to delete a text file...

    Am currently replacing the text file and writing... In fact, I need to open the file (after erasing the content) and write.

    I think that replace the file every time is not a good idea...

    So please let me know how to delete the text file.

    Thanks in advance.

    You can set the file size to zero using "Set File Size" in the palette of advanced file i/o.

  • AppleScript - extraire extract values from a table, create a text file with these values

    Hello world

    Lets say I have a table that looks a bit like this

    And this table I would create 2 text files (or even more, depending on how many switchnames are there) who look a bit like these

    Is it still possible?

    I suppose to create a Service (which can be called in numbers) with Automator which includes an Applescript script - but - no idea since the script is not one of my strong suits.

    There is not need to be perfect, because tables are not necessarily the model presented above - so to tweek the script to the application will be necessary. The text files can be created/saved in the same folder as the file numbers is in.

    Y at - it script-genius out there?

    See you soon

    Florian

    Select the column of fist of the data, and then run this script by copying the Forum and paste it into the script editor.  The files will appear on the desktop

    say application "Numbers".

    say front document to tell the worksheet active

    say ( class is worn) fromfirst table whose selection range

    selectionRange defined in column 1 of the selection

    set cnt to 0

    the value destRange for range

    the value currentList to {}

    -the list of switches

    Repeat with acellule in selectionRange cells

    -say acellule to set the value on the NTC

    pass the value to the value of cell

    if and ((cnt > 0) (switch is not missing value) and (currentList is not contain switch)) then

    switch and the value in the currentList currentList

    end if

    NTC put to the cnt + 1

    end Repeat

    -Display dialog box "to the list of items is:" & currentList & "a list" & (currentList County) ".

    Repeat with aswitch in currentList

    " game textOut to '# Script generated with Applescript for switch' & aswitch &"

    # on "& (today's date) &"

    !

    conf t

    "

    set cnt to 0

    Repeat with acellule in selectionRange cells

    -say acellule to set the value on the NTC

    pass the value to the value of cell

    -Display dialog "aswitch is []" & aswitch & "] and switch is []" & switch & "]".

    if (aswitch contains the switch) then

    the value cellCol to address a column of first cell of acellule

    address of line of first cell value cellRow in of acellule

    value to the aport (value of the cell of the column (cellCol + 1) cellRow) integer

    the value vlan for the (value of the cell cellRow of column (cellCol + 2)) integer

    the value desc to the (value of the cell cellRow of column (cellCol + 3))

    " put to textOut textOut &.

    !

    "" IG 1/0 interface / "& aport &.

    switchport mode access

    switchport access vlan "" & vlan & ""

    Description LINK TO "" & desc & ""

    "

    on the other

    -Display dialog box "did not: []" & aswitch & "] and []" & switch & "]".

    end if

    NTC put to the cnt + 1

    end Repeat

    Set myFile to open for access (path to the Office as text) & aswitch & '_output.txt' the with write permission

    textOut write to myFile

    MyFile close access

    end Repeat

    end say

    end say

    end say

  • How can I save an email as a text file before you delete it my Inbox?

    Some emails I want to save on my computer so that I can view without opening to the top of my email. I'm used to be able to do this by registering in a document as a text file folder. (Outlook express). I don't find this capablity in Thunderbird. If it is there, I have not found it.

    File | Register under gives you several options. By default, it will save in an .eml file, which will need an e-mail client to display. You can usually save drag-and-drop, but that creates an .eml file too.

    You can save as HTML by putting in a file html extension when you do file | Save as.

    This add-on:

    https://NIC-NAC-project.org/~kaosmos/mboximport-en.html

    offers several options to save one or more messages in different formats.

  • The file c: Windows contains many text files. JOURNAL; Log.Old, HTML and. PRX files that are very old, dating back to 2003. These can be deleted?

    Examples: Wmprfnld.prx and SETUPpapi.log.old and Reglocs.old and Q .log # and KB #. Journal

    You can delete the log files, a .prx file could be created by one of the many programs. In Explorer if you check the properties of the prx file it can give you a clue

  • I'm doing a script that takes a list of e-mail from a text file and then allow me to select a save as a string. I found some ways to get the path of the file, but I'm in check by pulling the list

    I found some ways to get the path of the file, but I am defeated by pulling the list from that. the function of the path get gives me the path as "Macintosh Users:: Documents: extractedb.txt (myUsername).

    What I can't understand is how to get a dialog box to display a list that represents the content in the text file, I need to change the contents of the text file, I need the box to show me what I chose and I want to save my selection as a single string.
    e '.

    example of extractedb.txt information:

    [email protected]

    [email protected]

    [email protected]

    * has a random number of emails as well *.

    I want this is to pull those emails from the text file and turn them into a list so I can get to be a selection in my dialog box.

    Any help would be great = D

    Assuming you have a text file with your example e-mail addresses, the following AppleScript will read this file in a list (mf_List) and then use this list as input to choose among the list. Because multiple selection is allowed (control button), the output is sent to a list (sel_addr). We check if the Cancel button was pressed by testing for false and if this condition is met, we the script error.  Based on a single or multiple list item content of the list, display accordingly.

    game of mf to ((path to the folder as text) & "mail_list.txt")

    the value mf_List to {}

    the value sel_addr to {}

    the value mf_List to paragraphs of (read file mf)

    the value sel_addr to (choose from the list mf_List with title ¬

    ('Mail list' with multiple selections allowed without empty selection allowed)

    If sel_addr is equal to false then

    Error number-128

    return

    end if

    If length of sel_addr is equal to 1 then

    sel_addr display dialog box as text

    on the other

    the value Point to the text of TID to AppleScript delimiters

    the value Point text in AppleScript return delimiters

    display the dialog box elements of sel_addr in the text

    the value Text of point AppleScript delimiters to TID

    end if

    return

  • AprΦs the dΘmarrage, the text file named Guadeloupe is open. Any ideas on what this is?

    AprΦs the dΘmarrage of battery empty, a text file named Guadeloupe (which I didn't create) with a single (visible) line of the text with some strange characters is open along with other programs that start at startup. Now, I tried to locate the source of this file without success - it's as if the file does not exist. I did not always have this problem (or event) arrive, and I didn't know of any other cases when searching online.

    Any help or information will be greatly appreciated.

    I'm on an Early 2011 Macbook Pro 13 inches, 2.3 GHz, 8 GB ram i5 upgraded, under OS X 10.10.5.

    One of your connection objects may be causing the problem. Please select the login items tab in the users pane and groups of system preferences. Remove all items that you do not recognize. If you don't know which ones to delete, double-click on each to test.

    If a connection item is dimmed and cannot be deleted, click on the padlock icon in the lower left corner of the window and enter your login password when you are prompted. Then try again.

    To avoid confusion, please note that checking or unchecking the box next to a point of idle connection not she. You must remove the item from the list.

  • Cannot delete the plist file system.

    My Time Machine is not automatically back up my drive. He worked for some time (don't know why) and then stops working automatically. I tried to implement the procedure laid down by Linc Davis, delete the file com.apple.TimeMachine.plist, but make the message: 'com.apple.TimeMachine.plist' cannot be changed or deleted because it is required by OS X.  I tried to change the permissions in the file information window to include Administrator Read and Write (only has this permission system. Which translates the message: "the operation cannot be performed because you don't have the necessary authorization."

    Using the terminal window and sudo rm command produces the same message.

    I do a backup manually through the system preferences window, but it shows immediately that a backup disk has not been selected. Next time, I select the backup disk, perform a manual backup. Repeat the next time, I have run a manual backup.

    10.11.1 on new iMac, retina 5 K with 16 GB of memory running. Has made a migration to this previous computer Mac Pro 10.7.5.

    Also the Time Machine backup drive icon backup weather icon to see the Machine. Relaunch the Finder does not fix issue.

    Question: How can I delete the plist file?

    Thanks in advance for any advice.

    A bug in OS X 10.11.1 prevents automatic backups that happens when a desktop Mac (iMac, Mac mini or Mac Pro) is connected to a UPS (UPS) with the USB feature.

    Please, back up all data before proceeding.

    First, check the App Store for a later update to OS X. If it is available when you read this review, install it and see if the problem is resolved. I speak not beta versions.

    Otherwise, you can work around the bug as follows.

    These must be run as administrator. If you have only one user account, you are the administrator.

    Please triple - click anywhere in the line below on this page to select:

    sudo defaults write /Library/Preferences/com.apple.TimeMachine RequiresACPower 0

    Copy the selected text in the Clipboard by pressing Control-C key combination.

    Launch the Terminal application integrated in one of the following ways:

    ☞ Enter the first letters of his name in a Spotlight search. Select from the results (it should be at the top).

    ☞ In the Finder, select go utilities ▹ of menu bar or press the combination of keys shift-command-U. The application is in the folder that opens.

    ☞ Open LaunchPad and start typing the name.

    Paste in the Terminal window by pressing the command-V key combination. I tested these instructions only with the Safari browser. If you use another browser, you may need to press the return key after pasting. You will be asked for your login password. Nothing displayed when you type. Type carefully, and then press return. If you do not have a password, you will need to configure one before you can run the command. You can get a warning to be careful. Confirm. You don't need to display the warning.

    If you see a message that your user name "is not in the sudoers file", then you have not logged as an administrator. Log in as one and start over.

    Wait for a new line ending with a dollar sign ($) below what you entered. You can then quit Terminal.

    Restart the computer and test.

    (Credit for this solution for chrfr of logicielmac.com).

  • Not able to read a text file or binary

    I am reading in a file text or binary, as shown in the Blackberry "how - adds an application of plain text or binary files"

    http://www.BlackBerry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800620/How_To _...

    I use Eclipse 3.4.2 I implemented a project of Blackberry with the following structure:

    Test1 (project name)

    -src (folder)

    |   + com.name.xxx

    |   + com.name.yyy

    |            Test1.Java

    + NET_RIM_BLACKBERRY

    |

    -test

    I'm reading in the test file is at the level of the main project folder.  For example, the Test1.jdp file is located in the folder of the main project and the test file (text file or binary).  I am trying to access the file using the line of code below:

    Class classs = Class.forName(this.getClass().getName());
    
    InputStream is = classs.getResourceAsStream("/test");
    

    The getResourceAsStream indicates that the file will be in the same location as the location of the Test1.jdp file if the bar oblique is in front of the name of the file, or that it will look in the source for the main class file.  When I have the slash I get error

    CAFETERIA: could not find the test file

    I tried several different attempt to get to the CAFETERIA to find the file, but I'm running out of ideas and I would appreciate someone else's ideas on what to try.

    Thank you

    Thank you klyubin and stef

    I found a solution that works for me with Eclipse plug-ins, JDE.

    First, the example of Blackberry in the how-to (see original thread number) with test as file is named simply 'test '.  This does not work for me at all in Eclipse.  I gave up to place the file in the folder of the project Eclipse (main folder) and placed in the src folder, which of course gives a compile error because is not a Java file, and of course when using file name in my java code I changed the code correctly as in the first line that follows :

    
    // this will look in the source folder of the class // that myClass refers tois = myClass.getResourceAsStream("test.txt");
    
    // this is supposed to refer to a file called 'test' // in the source folder of the class that myClass refers to // but apparently for Eclipse it must have a .txt extension// as in the above exampleis = myClass.getResourceAsStream("test");
    
    // this is supposed to refer to a file called 'test' // in the main project folder but not apparenlty for Eclipseis = myClass.getResourceAsStream("/test");
    
    // this is supposed to refer to a file called 'test.txt' // in the main project folder but not apparenlty for Eclipseis = myClass.getResourceAsStream("/test.txt");             } 
    

    Note: I was also getting the error message when I place the file named "test" in the src below directory.  I managed to get rid of this error message by configuring the path building (similar to deleting the file of the JDP file including klyubin suggested above for Blackberry JDE ordinary rather than the plugin Eclipse) to remove the file 'test' for compiling so I would not get the compile error.

    However, this was not my main problem - if you name the file test.txt and place it in the src directory you do not get this error I believe.

    Errors during construction

    Errors running builder "Blackberry resources Builder" on the project...

    Could not compile files

    java.io.FileNotFoundException: C:\path to the file I had added in the directory\.rrh of the source (or some truncation of the file name .rrh - for example te.rrh)

    Finally, I have checked the jar (as klyubin suggested) file that is created when I place the file 'test' or 'test.txt' in my Eclipse project main folder.  The jar file did not contain the name file and so when I run in the Simulator, the file is not found.  Even when I put the file in the jar (main directory) myself the Simulator still could not find the file.   When I placed the test.txt file in my directory src the jar resulting file contains the file named and the Simulator can find the file ok.

    So, it seems to me that for the plug-in Eclipse JDE contextual explanation of the method getResourceAsStream does not apply as described at this time.

    getResourceAsStream

    public InputStream getResourceAsStream(String name)
    

    Looking for a resource with a given name. This method returns null if no resource with this name is found. The rules looking for resources associated with a given class are specific profile. RIM implementation notes: this method searches the resource from the directory in which the current JDP project file is located. By default, it is assumed that this JDP file resides in the parent directory of the package of the current project space. Thus, the package space tree (for example, com/rim/PackageName) is added to name so that the search begins from this space package, that is, in the source directory of the current project. However, if the current JDP project file does not lie in its presumed location, the behavior above prevent the resource located. In this case, the user must add a slash (/) in the name of the resource before calling getResourceAsStream. This treats the name as an absolute path, which is compared to a tree whose root is the location of the JDP file. Parameters: name - name of the desired resource Returns: a java.io.InputStream object. Since: JDK1.1

    If Alain klyubin (or someone else) can enlighten us more on why the file should be named *.txt to find the file in the source directory, which can be useful to me and others in the future.  My real goal is to read in an image file named *.jpeg.  We'll see how it goes.

    And thank you klyubin for the suggested code change which I had also found in another thread...

    // this was more than what was necessary//Class myClass = Class.forName(this.getClass().getName());
    
    // this is simpler  Class myClass = this.getClass();
    

    And so many other Eclipse users who try to follow the Blackberry How To - add a text or a binary file in an application, do not forget to consult the file name in your code java as in the examples that I gave above.

  • How to clear the contents in plain text file?

    Can someone tell me how to remove all of the content in the plain text file!

    Send samples if you have for reference

    Use the FileConnection.delete method and the FileConnection.create method to remove and create a file.

  • I inadvertently deleted a customer file in the creaticve folder has a cloud way to recover, please someone can help me?

    I inadvertently deleted a customer file in the creaticve folder has a cloud way to recover, please someone can help me?

    Hello David,.

    You can take a look at desktop Adobe Creative Cloud application: Questions and answers > what happens if I delete the files in my folder of Creative Cloud Files? > I quote the entire text, so you can find better it: "synchronize destruction file for the creative cloud and other equipment related to the account. The files deleted from the Creative Cloud Files folder are first placed in the section of the archive files from the files page. It is similarly of the files deleted from the files page. Your quota account thus archived files, so it is necessary to remove the files permanently to free up storage space. You can browse your files in the files of the site creative cloud heritage to restore, view decompress or permanently delete files to free storage.

    Hans-Günter

  • [Help] Need help to remove a string in the text file

    Hi all

    I have a text like this

    REPORT

    Wednesday, June 10, 2015 14:31:56

    **********************************************************************************

    HOST: 10.9.1.185

    TestVM is turned off

    **********************************************************************************

    HOST: 10.9.0.84

    All virtual machines are turned off

    **********************************************************************************

    HOST: 10.9.0.85

    **********************************************************************************

    HOST: 10.9.0.86

    I want to remove the

    **********************************************************************************

    HOST: 10.9.0.85

    **********************************************************************************

    HOST: 10.9.0.86

    because there is no information after the HOST 10.9.0.85 or: 10.9.0.86

    It will reduce the content of the report

    I need a script to delete this text

    Could someone help me?

    Thank you for your help

    What generates the report? It is probably easier to just do not write to the file in the first place...

  • I DELETED MY PDF FILES AND AGAIN USING THE RECOVERY SOFTWARE I FIND ALL MY FILES BUT NOW WHEN I OPEN FILES THAT IT SHOWS (THE FILE MAY BE CORRUPTED OR NOT SUPPORTED FORMAT.NO HOW CAN I OPEN THE FILES.) ALL OF THEM ARE MY DOCUMENTS IS VERY IMPORTANT. PLEAS

    I DELETED MY PDF FILES AND AGAIN USING THE RECOVERY SOFTWARE I FIND ALL MY FILES BUT NOW WHEN I OPEN FILES THAT IT SHOWS (THE FILE MAY BE CORRUPTED OR NOT SUPPORTED FORMAT.NO HOW CAN I OPEN THE FILES.) ALL OF THEM ARE MY DOCUMENTS IS VERY IMPORTANT. PLEASE PROVIDE ME WITH A

    Deleted file recovery can recover incomplete files, i.e. the part of these files may be missing.  Recover deleted files is much more reliable if recovery of a backup, instead of using recovery software.

    These things depend on the operating system and the file system.

    One thing, you can see: open one of these files damaged with a text editor, and then make sure that the constant % PDF is somewhere in the first 1024 bytes.

    PS please do not post ALL uppercase; It is very difficult to read!

  • delete the text of an image and add the new text to the image without damaging the bottom.

    Hi, I have an image with a text written on it. I want to delete this text and add text, am new to... tried looking everywhere but could not find anything on this... How can I do this in artificial intelligence?

    Open the vector file, use the direct Selection tool, select the text and delete. Add the text you want to add then save for web (make your .jpeg) or copy and paste in something like Photoshop and create the file in this way.

  • Deleting the same files of many virtual machines remotely

    Hi all

    I tried to delete the same file several virtual machines remotely using the following script PowerCLI:

    $a = Get - VM | %{

    foreach ($nic as $_.) Guest.Nics) {}
    Write-output $nic. IPAddress
    }
    }
    foreach ($i in $a)
    {$b = get-WmiOBJECT-query "SELECT * from CIM_DataFile where Name='C:\\test\\deleteme.exe'"-computername $i}
    $b.delete)

    }

    It works perfectly when I run the script on the host virtual machines while I am running the script PowerCLI. When I Connect-viserver to another host however and try to run the script, I get the dreaded "RPC server is unavailable error (HRESULT: 0x800706BA)" for Get-WmiObject.  Virtual machines don't have Windows Firewall and have all TCP/IP, RPC and WMI services started, so who could eliminate any possibility.

    I am also able to run other scripts that use the Get-wmiobject across all virtual machines such as scripts to change the DNS or Netbios name across many machines on different hosts.

    Any comments would be greatly appreciated and please feel free to comment if you know maybe other ways which can delete files on multiple virtual machines in any other way.  Installation PowerCLI to run the script locally on each host would be a laborious process to do.

    Thank you very much!

    Best regards

    To solve the problem with the quotes, you can use double quotes inside the string. Like this:

    «del "«c:\documents and settings\text.exe»»»

    Or you can use for the string single quotes and double quotes inside:

    "del"c:\documents and settings\text.exe"

Maybe you are looking for