• Become a Power user Intro to AutoHotkey Intermediate AutoHotkey Intermediate Objects GUIs are Easy w/AutoHotkey Painlessly switch from V1 to V2

File and Folder manipulation

Our AutoHotkey webinar on copying, editing and moving files and folders had some amazing scripts.  Watch the webinar and get the files below

File and Folder Manipulation
Select and Run

The key idea of the video is to demonstrate the various functions and techniques of file management in AutoHotkey, including manipulating, retrieving, reading, writing, and moving files and folders.

  • 00:00 📝 The webinar discusses the functions of AutoHotkey, including file management, screen locking, music control, and battery saving.
    • The webinar discusses the various functions and capabilities of AutoHotkey, including copying, moving, deleting, creating, editing, and saving files.
    • The speaker discusses the control and organization of the webinar, including the option to ask questions through chat or by raising one’s hand, and the decision to mute participants during the first hour to avoid chaos.
    • The speaker discusses a script they wrote to lock their computer by killing the power to their monitors and blocking key combinations, demonstrating the code and explaining how it works.
    • The speaker discusses a script that allows them to pause and control their music even when their screen is locked, and mentions that they have a separate hotkey to launch and kill the script.
    • The apps key, located to the right of the spacebar on some keyboards, can be used as a modifier key to launch programs and is also known as the context menu key.
    • The speaker discusses a simple script that can be used to save battery energy by disabling the screen display.
  • 09:41 📝 The speaker discusses various topics related to files and folders in AutoHotkey, including moving, copying, deleting, creating, editing, and encoding, and provides examples of file operations using AutoHotkey scripting language.
    • The speaker discusses various topics related to files and folders, including moving, copying, deleting, creating, editing, and encoding, and provides examples of file copy/move/delete operations using AutoHotkey.
    • The speaker demonstrates how to copy a file from one folder to another using AutoHotkey scripting language.
    • The speaker demonstrates how to create and copy files and folders using AutoHotkey, including specifying subfolders and changing file extensions.
    • The speaker discusses the functionality of creating subfolders and deleting files using AutoHotkey, emphasizing the simplicity and ease of use.
    • The speaker discusses different modes and commands in AutoHotkey for copying directories and files recursively, and highlights the case sensitivity of the “loop files” command.
    • Not returning a value in a sub loop can cause a fall through in the script, as labels do not stop the script.
  • 18:55 📝 The speaker demonstrates how to manipulate and retrieve information from files and folders using AutoHotkey, including extracting file names, calculating folder sizes, and deleting files with specific extensions, and discusses the concept of encoding files and folders.
    • The speaker demonstrates how to manipulate and retrieve information from files and folders using AutoHotkey, including extracting file names, calculating folder sizes, and deleting files with specific extensions.
    • The speaker discusses examining and deleting files in a loop, noting that the loop may continue running indefinitely without a counter, and suggests running a test to confirm the deletion of PNG files.
    • The speaker demonstrates how to use AutoHotkey to create a ListView and display the files in a folder, showcasing the simplicity and power of this feature.
    • The speaker discusses the concept of encoding files and folders, explaining that different encodings store characters differently on a computer and that Unicode is a way for the computer to understand which characters are which.
    • Stick to using utf-8 for file encoding as it eliminates the need to worry about different character types, although it may increase file size compared to ANSI files.
    • Stick with using the 32-bit unicode version of AutoHotkey unless you have specific reasons for using the 64-bit version, and avoid using the SI version code as it can lead to issues that take hours to realize.
  • 30:33 📝 The speaker demonstrates how to read, write, and append files in AutoHotkey, emphasizing the importance of adding a new line at the end of each row and working with Unicode to avoid wiping out special characters.
    • The speaker demonstrates the use of the file read and file append functions in AutoHotkey, providing an example of appending text to a file and deleting the file before running the script.
    • The speaker demonstrates how to create and append data to a file in AutoHotkey, emphasizing the importance of adding a new line at the end of each row.
    • When reloading a file, it appends the existing data and can generate a blank file if no data is provided, but if scraping data from a website, it is better to keep appending rather than deleting.
    • The speaker demonstrates how to read and write files using AutoHotkey, including using the utf-8 encoding and storing the file contents in a variable.
    • Working with Unicode is important when dealing with files from different countries, as special characters like Chinese characters and emojis can get wiped out if not properly handled.
  • 36:48 📝 The speaker discusses the installation of AutoHotkey and recommends using the 32-bit version for compatibility, while also explaining the “loop file read” command for reading files and manipulating variables.
    • The 64-bit version of AutoHotkey may be faster for certain tasks, but it is recommended to use the 32-bit version for compatibility reasons and because the speed increase is not significant.
    • The speaker discusses the installation of the Unicode 32-bit version of AutoHotkey and mentions that both the 32-bit and 64-bit versions are available, with the 32-bit version being connected to the ANSI version.
    • The speaker discusses the “loop file read” command in AutoHotkey, which allows users to loop over files and read in the files or read a specific line from the file.
    • Loop over a list of job titles and display a message box for each one, using a special variable to manipulate the current row.
  • 41:45 📝 The speaker demonstrates the use of the “File” object in AutoHotkey for efficient and controlled manipulation of files, including sorting, extracting, and inserting text, while cautioning against the impractical use of the “FileReadLine” command within a loop.
    • The speaker demonstrates importing and displaying the first hundred items in a listview, highlighting the ability to sort, extract, and manipulate the items.
    • The file read line command retrieves the contents of a specific line in a file, but it may still process the other lines.
    • Many users have used the “FileReadLine” command in an impractical manner within a loop, but it is strongly recommended to use the “File” object instead, which allows for programmatically connecting to and manipulating files.
    • The file object in AutoHotkey allows for more efficient writing and closing of files, especially when dealing with a large number of lines.
    • The file object in AutoHotkey provides more control over working with files, allowing for actions such as inserting text in the middle of a file or replacing content, while the file append and file read commands require reading the content into a variable and performing actions on it before deleting the old file and appending to a new one.
    • Opening a file with specific privileges and in a specific format can be more complex, but it is worth the effort as demonstrated in the example provided.
  • 49:07 📝 The speaker demonstrates file manipulation techniques in AutoHotkey, including adding line returns, reading and writing files, grabbing the last row of data, and using seek and file system objects.
    • The speaker demonstrates how to add line returns to a file using AutoHotkey, showing an example where the length of the file increases after adding the line returns.
    • Make sure to close the file after using it to free it up for other programs, and when reading a file, each time you call the read function, it moves on to the next row.
    • You can move the file pointer to specify which line to read using functions like read line and write line, and there are additional functions like seek for more advanced file manipulation.
    • The speaker demonstrates a quick and easy way to grab the last row of data from a large file using AutoHotkey.
    • The speaker discusses various file and folder manipulation techniques in AutoHotkey, including using seek and file system objects, DLL calls, and copying and moving files.
    • The speaker is trying to find a specific file and is apologizing for the confusion.
  • 57:45 📝 The speaker demonstrates how to copy or move files using the status bar and cancel the action, as well as using the Windows file system object in AutoHotkey for obtaining file information.
    • The speaker demonstrates a feature that shows the status bar and allows for copying or moving files, with the option to cancel the action.
    • The speaker demonstrates the use of the Windows file system object in AutoHotkey for obtaining file information.
all right so hello everyone my name is Joe Glines and I’m here at a Dallas and we’re getting ready to start our AutoHotkey webinar and my colleague Jackie Sztuk watching just yourself yeah hello I’m Jack  yeah I’m here took that the with Joe Glines one more time yeah so happy to be here to talk about ourHotkey one more time and and so I think a lot of you guys have assemblies but of course people watch these later soneither of us are programmers we don’t come back from a programming background
but we’ve been using out a HotStrings right no object-oriented stuff and it does so much more I mean I still I’m so glad I used it back then but the stuff it does I do with it now is just insane compared
to what I used to use it for yeah I think I switched my first window back in 12 or something like that where all it actually did was just remove move a value from one window to the other aha switching back and forth so yeah that was my first very simple script so in this this webinar is going to be on both copying and moving and deleting files and then also creating and editing and saving files and the content of them and so we had 75 registrants of course not everyone shows that but we encourage people just
register because and you get an email with the resources and links after right now because there’s so many people right if we weren’t all muted it would sound like a madhouse I was actually on a call through the day where they had like three or four people and everyone it was just really a cluster because everyone kept trying to over talk each other and so this is how we we control that is the first our Jackie and I will go through our deck there’s a way you can raise your hand or you can just in the
chat you can ask a question and so just feel free to ask questions air or if your question is so complex that you’d rather ask it I can unmute your mic if you want and then you can ask it but for the first hour we have it set up where you can’t omit yourself and it’s not because we love hearing ourselves talk that’s just because it would be chaos so without further ado we’re gonna get started off here this first one and it’s kind of ironicis that I did test this butthis is a script that I use
like when I used to work in the corporate world and I could never walk away from my computer without locking using like the Windows key and hit L to lock it and of course then I’d come back and have this crazy like you know eight character password that would have you know lowercase uppercase numbers letters special characters and have to type it in every time and it really annoyed me so I wrote a program thatwhat it does is when I hit it and this is what’s funny is I could hit it right now but you guys won’t see anything but what it
does is it kills the power feed to all of my monitors and it also blocks any key combination from being pressed except for certain ones that I have opened up and let me show you the code but I really can’t demonstrate it this is the here’s my locker code so it first off just of course make sure there’s only one instance of it and this gives it a little bit of a sleep so basically I can let my fingers off the keyboard otherwise it tracks out and never goes into the sleep but then it jumps into a little set timer here every quarter of a
second and and goes and sends the sleep this is the sleep command this to here tells it to windows to kill the power to to all your monitors and basically just sits in this loop and keeps looping over it until I hit the apps key and in my case you then it will turn that off and it exits the app but the Auto thing I do is you can see here I set upHotkeyboard and hit them and it won’t it won’t actually do
anything and so it for all in fact it it it is locked my computer’s locked I actually turned off a couple like this the the media because sometimes I’ll have music on and I wanted to be able to pause the music even if the the window was if my screen was locked up and I can turn the the oh I can mute it I can pause it and I can turn the music up and down but this is how it works I’ll make it a VA thing we do in this we have available after the webinar we also record the webinar and be on youtube I
see doctors or a question of block input but then but I don’t want people even seeing my screen is what I boil down to right is is mine kills it because even if I would get literally get a ticket if my screen was up and I was not near my computer and they waited for more than a minute I would literally get a ticket written and left on my computer I’m regardless of whether they could type anything or not well yeah I’m I I’m not gonna try to change my theme but I can zoom in a little but anyway we’ll give you I know
these are hard to see you don’t don’t get me wrong but we’ll we’ll share the code later on Oh instead of list the Hotkeys oh I don’t know maybe that worked fine this I did this again this was one of my first scripts like a lifetime ago and it works and I’ve just never gone back and played with it so anyway like I said I demonstrate it but it you will guys won’t see anything cuz it doesn’t kill my video card it just kills my mother power to my monitors so I would lose everything oh and the other
thing to point out isI have a Hotkey no
the apps key if you look down in your keyboard to the right of your spacebar if you have one there’s there’s an alt key and then there’s this other key that looks like it almost looks like AI has a small picture of a calculator on it and then to the right of that one is the right control key so to the right of your spacebar between the right alt and the right control is a key and on a lot of keyboards it’s the applications key is what it’s actually called however some keyboards don’t have it
they have the remember Jackie’s at the all graph or something like that our graph yeah yeah old gr ground so not all keyboards have it I purposely because I use it let me let me pull up my main this is my main AutoHotkey in my head right it helps me
remember what it is but but yeah that’s it’s just that key and so I purposely buy keyboards to make sure they have it because I use it a lot yeah just saying I’m falling in and out of audio so I don’t have some things I hear and some things I don’t but yeah yeah I don’t know I don’t have an apps key either I simply have the Alt key or the Windows key and of course the Menu key and then the ctrl key so yeah and it’s probably somewhere able to activate it somehow yeah Jean I think you’re right it’s um
it’s also can be known as the context menu key cuz and if you’re not if you haven’t tied it to anything it will trigger right your context menu which is what a really long time ago I used to use it for a really really long time ago so anyway it’s not an amazing I mean it is one of by far these simplest scripts I’ve ever had but boy I use it all the time because the other thing I use it for is I’ll be sitting here and like or I’ll be in a meeting and my laptop is using energy powering my my display and
nothing’s going on and so I can just hit a button and it it will you know kill the feed to the screen and just save my battery energy it isn’t that I wanted to lock it it’s just I want to save the energy yeah alright so that was that one let me go ahead and close that the simplified of this alright and we’ll get into the next one all right so here’s the overall at a high level topic of we’re dealing with files and folders this I’ll send out the link this hyperlink is a zip file that has every
script that we review today in it and so when you see it actually I’ll try to remember to put it in the email so you have it so you’ll have them all as attachments but it’ll be on my webpage also where we we have on Michelle and so we’re gonna cover moving copying deleting files and folders and then as I said creating editing files and in the dreaded to me dreaded encoding which confused me is obvious still I don’t understand it fully grasp it I at least understand the concept but I’m
definitely no pro on it alright so to start off with just doing some file copy/move delete now a lot of this here I don’t don’t beat me up too much I literally copied and pasted from the AutoHotkey support because a lot of the stuff is very straightforward and I took some of the more important kind of interesting parts let me a little extra spacing in here but if you haven’t used it already to copy files and the move files file copy you know you just put in the the pattern you want in the destination and then you put in whatever
fly you’re using and it will copy a single folder or files but if you want to do a lot of them use file copied Durer to copy the contents of the folder instead of all its files and subfolders let me show the first script here just to I think it’s it’s a lot easier to talk to this this is my first one yes so and let me come over here and so under files to paniculata let’s see here we have that’s the path let’s so so here’s my script right this we’re gonna first go sub to here and
we’re going to call this line where we’re gonna copy this example 1 dot txt into the sub folder right here so let’s make sure I don’t I’m gonna get rid of that ok and it’s gonna return so let me launch my script and now when I run it actually let’s do this way all right here we go when I run it there I just copied that example 1 dot txt from this folder here right into that sub folder and this was the call and here I’ve defined my path just cuz I was gonna reuse it and so I put it there and and
then I just called it here and dumped told it where to put it now if I had wanted to do the same thing but give it a different name so let’s say I want to put it in the same folder so here I’m using the same folder twice right I’m copying it I’m making a copy of it and actually let’s say let’s let’s better name this there now when I save this and reload it and I yeah I’ve got a comment to that out and now in here let me go up one so here you’ll notice that here’s the example one and when I run it
there it just created the file in the same folder because I this time I didn’t tell it a subfolder I just gave it a different name right so it’s very simple straightforward and then this last one and here I’m not gonna run it butit’s basically the same thing but I’m changing the extension right it’s the same exact same thing as this but I’m just easily changing the extension I’m giving it yeah and and if this script was placed in the same folder as the actual example one text file yeah you
wouldn’t actually need to specify at the path right that’s a good point yeah yeah yep it assumes the local folder if you haven’t given it the path to it all right and then so let’s go ahead and we’re gonna switch over now to the copy folders and then this first one let me see here so we’re gonna copy this subfolder and we’re gonna place it into folder copy and so in this one I want to be that’s the subfolder and so that is it thing is gonna put it right here is that right it should yeah yeah okay some of
whoops save it reload it now when I run actually mm-hmm so here we have two files in there let’s go back up now when I run it so it created folder copy in the same subfolder or source same folder with and there’s the contents yeah and this next exampleoh I did want to point out what I do like about this one excuse the typo isif you have if you’re trying to build a a sub folder structuring if it doesn’t exist this command will automatically create it and so oh it’s gonna create oh I didn’t
realize it I’m sorry I put in a crate directory and so this folder copy subfolder sub folder so when I save this reload it and run it and I should have it over here so folder copy was I think I was in there oh no yeah here subfolder subfolder so see all these sub folders I didn’t have to call that you know four different times it just ran once mm-hmm and I was able to create that subfolder with it yeah yeah it’s it’s it’s very easy and simple to use and of course you need to know how file paths
are formatted yeah nothing like that it’s very simple to use these other ones there are very similar the file delete we’re actually going to demonstrate that in a later script but I’ll cover that then but we have the the links here and stuff we’ll share them again this is straight from the AutoHotkey support stuff is nothing no rocket science on these this next one I don’t use it that often but it is an interesting functionality and so come back to studio oh here so the one thing I do want to
put out here with this loop files this this files here it’s case sensitive that’s why I highlighted the the red F so make sure you do it exactly like that and then you can these are the main different modes I think you can use numbers also in place of them but I just put in the the letters here so for if you want to copy the directories or the files and do recursive write those that’s what you put in anything between brackets is optional on any sort of command and in AutoHotkey and then there are these when
you’re it retrieves the folders one at a time as it loops over them and you can do different things to them and then there’s this list of all these special variables right that you can have access to inside that loop so let me let me actually the files already open then we jump to the files and folders here we go alright so we’re gonna start off with this first one and we’re gonna look at in the folder path and get all the text files and then we’re gonna do it recursively and that’s what this R is
doing here oh I need to exit out of the script and lunch this one I find it interesting that the loop files is actually case sensitive there must be one of the only another any yeah yeah there’s at least very few yeah in recursive can is it means it keeps drilling down right regardless of how many folders and subfolders it’ll automatically go beneath it and get everything and keep looping yeah which obviously you can understand why it’s a great ability to have it’s also important to know it is
there because if you didn’t want it and it’s doing it that could be really bad – yeah so here oh then we’re gonna put them so oh you know what I didn’t I didn’t have a mess oh look at I didn’t have a return that’s why know that that’s if I correct me if I’m wrong and it’s called a fall a fall Oh what fall helpful net well when I forgot to return a fall through I think that’s called I forgot to add a return and my sub loop and yeah you could probably call it a fall through
yeah but yeah it just continues to flow of the script yeah yeah so labels don’t stop the script so that’s right just right it just it’s just I think that’s called a fault anyway so it went in this directory which I defined up here if I was to manipulate and got me all the text files recursively and and so it went got him and then I dumped it this is in in studio this is a the debug window but Maestri have built a function that allow me to dump text to it because in site I had that function for using the output
window and it’s just nice because I don’t have to build a GUI every time I can just dump stuff to it so here I got a list of a notice here I did the full path right but this is one of those special these these variables here right so let’s just let’s just play with it real quickly let’s change this to a new file name so imma save as’ reload it and run it oh and I oh I had this other one here we go so so notice how that changed is we don’t have the full path right it’s just the file name and so that’s how we’re
using these special variables inside that and so let’s go on to the next one I know I don’t think I think for most you guys this is pretty you’ve done this right but here here’s a great example where we’re gonna get you out what if I wanted to know that the folder size of a given folder and all its contents and so here we’re gonna jump down to folder size we’re gonna get a list of all the files in my temp folder and then it’s gonna start adding them it loops over them to add them up right is that each
file starts adding them up and then it finally presents you with a message box is saying I have five megabytes in my temp folder under C colon slash temp the loop folders let’s see here so this one we D is telling it to loop the folders and I didn’t have the R in there so it’s not recursive and let’s see what the so that gave me under my seat : / I said look there get me all the folders and so here are the folders under my C Drive this next one here was when I had written years and a lifetime ago and it
was just an example of what if I wanted to you know look in certain places in delete file types of certain extensions and so I first made a list of extensions I shall look at that there’s that’s a CV I I think it was supposed to be like that yeah but it’ll it will it’ll it’ll then loop over them in each well I’ve defined them here and then I start looping over these and inside here says hey if the file extension I’m looking at is in this list and then this is what it examinesI easily could have put
those down here if I if I cared to but this way if I use them over and over outside the loop they’d still be there then go ahead and delete it if not just stop and then basically when it’s done it’ll it’ll break the loop otherwise they would keep running forever because I don’t have a counter on this let me see shouldn’t it only loophole with them once well you know I would think so however when I ran it earlier it kept running and I actually I had firt when I first cuz like I said I wrote this long
time ago I commented these out and I was running it and it kept running and it didn’t just say we turned you know what I would check the very you know check check in here and see what I was doing it was still doing something I agree with you though I mean I’m happy let’s let’s let’s ticket a test run here so let’s see there’s pee and geez do I have PNG yeah PNG is in here let’s comment these out let me make sure I’ve got delete files you know that’s right let me go back here I’m gonna run it so
it deleted some of the things right you saw the PNG files go away yeah now let’s see what it’s doing so see this oh wait a minute oh it did now it’s not ice maybe maybe when I did it I didn’t comment something out okay umm so now it is it’s I’m hitting f5 and it’s just saying it’s just sitting here right he got to the last return so so thank you Jackie I’m glad you have me double check that because it didn’t make sense to me but I I don’t know why I had that in there so
let’s go ahead and drop it there we go and then the last one and here I alluded to earlier we were just starting wasI I was demonstrating using a ListView and so here what we’re gonna do is I build a list view and I actually changed the font size it’s a little bigger I did manually create the headers for it but here are the special variables and now we’re gonna we’re gonna look at the files in my temp folder and we’re gonna dump them into a ListView this command here tells it to auto size it and now
when I run it so it just built a list of the files in my ListView apparently I should have done this before I deleted stuff but list used to me are just amazingly simple and that they’re so powerful is a great way to display a lot of your data it still works and so yeah but hey didn’t you actually have text in your loop file list to delete yeah you did yeah yeah interesting that then there actually is text files right well I agree yeah yeah maybe I stopped no I didn’t stop it anyway I’m not gonna
worry about it it did I mean we saw the pngs disappear we did you know but all right so we’re halfway through we and I’m kind of doing fast cuz we got a lot to cover but but that was basically showing the looping files and folders and so let me exit out of that script all right now all right final encoding okay so these different commands you know need to know what your encoding your file is built in and and as I was saying earlier I at least grasp the concept right that your computer needs to understand what what a a is and what
Abby is on what a C is in and different encodings will you know be stored differently on your computer to tell you know your your your program that that’s an a does that sound is that you better summarize it Jackie no I don’t think I can what what I think I learned back there is that these UDF’s are just very long lists of actual characters with a specific placement and with a specific index so yeah the encoding actually just is a different list of characters so if you like we use Unicode oh he cut out yeah I probably come back
actually here me my computer you keep saying that I’m having a bad connection we here yeah now but yeah to me it seems like okay and that that’s the way I see it it’s just the way for the computer to know which churches which where a lookup table basically right not hearing me yeah and so yeah yeah and so the one thing I say is like you know 20 years ago maybe 30 years ago EMC was fine right it was like you know it was most things were in English and it wasn’t an issue nowadays and there’s
so many other different types of characters these days I I stick to I use utf-8 with everything and just say then I don’t have to for the most part I don’t have to worry about anything and so I try to set everything to utf-8 in this number actually where I thought I had on this page here code page here we go you know and this stupid let me let me let me pull it up to show you the the lookup table right and and the reason why so see this 6501 right that’s utf-8 or a unicode utf-8 that that’s why for
utf-8 at 6501 and then you could of course look up whatever other encoding you want and specify it but honestly like I said if I were you I would just stick with the file size granted that makes compared to ANSI files it makes the files bigger because it takes more characters to save stuff but file size does nothing compared to what it used to be and and so typically we have plenty of space and so I would always default to utf-8 the other thing which I cheated on is that some of the most of the these commands you can either use
CP 60 501 or 65,000 one excuse me or the word utf-8 you could put this in there in that place but not all of them do and so I wanted to keep it simple and just leave it as put in this or at least use the numbers because one of them actually you only put in the I think it’s the P 6500 one and not the CP butanyway so you’ll get that’s where these numbers are coming from oh and the other one of course is if you’re you know I Jackie and I both we recommend you stick with using the 32-bit unicode
version of AutoHotkey unless you have particular reasons why you’re using 64-bit and I would say do not use an SI version code of AutoHotkey cos you can just end up getting stuck for things that take you hours to realize it’s just something that you you should have upgraded and used the unicode version of I can’t hear you Jackie oh I’m not saying much because yeah even even the sound from your end is choppy on my end so yeah maybe if you killed your video feed it would help with the bandwidth
you think yeah maybe I can try it at least maybe an ro alright so let’s go ahead and get into the next one so file read and file a pen and that this for me is my bread and butter I use it easily daily and and here’s a perfect example of the the file read to read in Unicode this you put in a star CP six five zero zero one and then the file path right so let’s go ahead and go to my file read and final append example here so oh actually just to make it more make it so it makes more sense and I’m gonna first
start with this commented out and we’re just going to do the file offend enemy now the other scripts already exited and where are we working out of this the files to manipulate files to manipulate let me jump back to that folder how there is okay files to append and so this is gonna pend this and then a new line is new line my new line text and then a line break right so when I run it I launched it and I run it and actually a you know night well this right here file delete file append example one let’s let’s go ahead
and manually delete that just so we can see it happen alright so now when I run it see it just created this file right and when I pop it open that’s the file it created and it put them each of those and new lines because I put in that new line feed after it and then there’s one at the end because I add a new line here in the return so here here’s one thing to keep in mind when you’re using this command which I almost everytime forget and it’s not a big deal it just means I have to run of the second time is don’t
forget when you’re appending a lot of data each row to add your your new your line returned at the end of the row so if this isn’t a loop you want it to you know what I typically do will up here have like my data feed those are variables and then I’ll put in what I need to remember is to add that at the end and then down here what I would do is when it’s a when it’s a variable you’d put it in like that right and then that would write the contents of your data to there and especially if line 11
here was in a loop right it would build that up because this is appending it each time each time as it passes through it over it and then it would build up and build up build up and then finally append to it hopefully that made sense now what I wanted to demonstrate next is let’s not I’m not gonna delete that file and I’m gonna rerun this so let me save it and let’s come back here where do I go now I’m gonna rerun it and now when I when I reload this file notice it’s in here twice right that’s because it literally
is a file append right it’s going to take what was there and it’s gonna stack on what’s beneath it what’s beneath it what’s beneath it it doesn’t care that if there’s something there or not it goes ahead and if you put nothing it’ll actually generate a blank file if you put no data in it it’ll generate a blank file and so that’s why what the first time I ran this if if I if I’m writing like a header row you know I want to say hey if there’s if there’s no file right
a header row if there’s a file there I can either rewrite the header row you know or I can delete the full the file itself and then write the header own go on but what if I was scraping data from a website and had a lot of it and in my script crashed you know I wouldn’t I would want to go ahead and just keep appending I wouldn’t want to delete stuff and of course it would have the header at the very top now let’s go ahead and but I’m gonna go ahead and I’m gonna leave this deleting it so we don’t
confuse it every time cuz now I’m gonna run both so I’m going to file pen and then a file read in here so let me go oh sorry and in here I do have the UCF – eight the encoding to save it as utf-8 file and now I’m gonna save it we load it and when I run it let’s see it’s gonna it’s going to dump it out to my output window here it’s gonna read it in and this is using that utf-8 encoding this is one of those to me it’s a weird one as I put star P six five zero zero one to keep it Unicode compliant and
when I read it in so that just they did both it actually all three things it deleted the file it it wrote this text to my file and then I read the file and stored it in this variable called var and then I dumped that into my output window yeah yeah and and of course it’s it’s good to know all of this but to me everything I do is actually done in Unicode and that’s the standard code page for for my version of Windows and stuff like that so it’s not something I really think that much about and here
you don’t have any real special characters so you don’t actually see this but but yeah it’s good to know because when you work with files from let’s say another country or something like that it’s always good try to be be aware that this isn’t he well in and what I’ve run into is people’s names especially like with the webinar stuff right people’s names will will not they’ll lose that in yeas and and other Chinese characters they get completely wiped out and so and then thewhat do
they call it emojis often now right they’re all Unicode and so they Lou they don’t come through I saw a comment in here about the singing the Installer says 64-bit version is faster I think it’s possible for some things that you my guess probably would never use maybe it’s faster right yeah on a 64 on a 64-bit OS of course it can utilize more of that business but with a lot of the Windows applications being 32-bit still even though we have had access to 64 bits for a long time and when working
with them from AutoHotkey it is just simpler when you call Dells and other stuff like that to be on the same bit version so so that is why we recommend that in 32 version at least because the actual speed increase you would get from the 64 bit version is natural yep yeah and it the some library that are built in AutoHotkey don’t have a 64-bit version but I don’t know how common that is anymore and if it causes issue most most of time you know they work fine with each other but I have run into issues to your point Jackie where
the program I was connecting to was 64-bit and I wasn’t trying to connect with now here’s the other weird thing right you you tell AutoHotkey I’ll install the Unicode 32-bit v1 that is being put in your retro story and stuff like that try to run ourHotkey files
but yeah all of the v1 maybe I
do I do I do but the file the loop file read in file read line right and so this one you can loop over files and read in the files while you’re doing it or you can read a specific line from the file and so again I will share all this stuff here I’m not going to read the screen to you there’s a little bit of hints of why you pick one over the other but let me let me jump to that script this one and honestly I’ve virtually never use this this particular command so loop file read in here we’re gonna
I’m gonna dump everything into a list for you again and we’re gonna loop over files in Oh actually this is a okay sorry I’m remember this is my I have this really big file it’s called full list and it’s a bunch of people with their job titles and whatnot and so initially we’re gonna put a message box and show you this variable here this a loop read line that’ll be the the row that it’s currently on as it loops over it and and I’ll just let me see well I’m not gonna write over 100
but I’ll just break itso let’s go ahead and start it and run so actually this is my header row and that the one see the a index right that’s in any AutoHotkey loop a index works is your index of what it iteration you’re on of it and so now we’re manually going one line at a time and what’s great about it of course is now I can loop over this whole thing and I already have this special variable here for you know do whatever I want with that row and then and then proceed on to the next next
time it goes through it’s the next row and the next row and the next row oh actually let me see here oh oh maybe I do have another one after this oh no it’s this one okay so I think it was well we won’t know let me go on here right so let’s see what let’s keep that person because what I was going to demonstrate was I’m going to comment that out and now we’re gonna we’re gonna break we’re gonna import the first app 100 it’s gonna stop importing them and so we dumped that
into a list for you and see how here’s the first hundred right and here here’s number six and that’s what I was trying to show was yeah see how Connie I’m not gonna try to say that as a business analyst that’s we were iterating over one at a time right but I just very quickly iterated over the first hundred dumped him into a listview and then showed him up here and great thing also let’s use right you can you can build them where you can sort on them you can build them where you can highlight them in
double-click and extract them foe like I said maybe we’ll do that for the next webinar the oh sorry go ahead Jackie no it’s just loop read line yeah that that I to tells you quite a bit about what you’re actually doing or what’s in the variable but yeah you you could get the contents of the line with a few of the other variables so is it a dupe field as an example one field would also be a line so so you you have different options when actually looping over a file with in this manner but yeah
thethe next one and this this file read line so if you happen to know the exact line you’re looking for right and that was what here here I I said go get me the fifth line of this file and that’s this is the one I was thinking of so here this is it’s Rebecca oops I guess I so here’s Rebecca right and that’s what this command just went and got the fifth line in that file but if I remember reading correctly I think it actually still processes the other lines I don’t think it’s any faster is that
do you remember Jackie the fire read line it it to see an and process a large numbers one by one yeah if I remember right I read that I think this file read line actually still it doesn’t just jump to it as my point right I I do think it actually dump jumps to it in in in some manner okay but the problem is that a lot of people have used this command inside a loop so they’ve used file read line a index variable at the end so they’ve actually looked over the contents of the file and then within the block of the
loop they’ve actually put this command fire redline and at the end they’d used the variable a index yeah yeah I actually read one line at a time instead of actually using the building variable to do the same thing so that is why you actually have this de strongly recommended use of the command that is that is from other users actually using it in an impractical impractical manner that is not you right all right that’s now the file object is is amazingly cool and I meant to to try to get some time to go and do my test
that I initially did a couple years ago testing the speed of it the and hopefully you’ve seen our our webinar using calm objects but it’s a comma it allows you to programmatically connect to it in manipulate things and basically you can also tell it hey open this file do all this stuff to it you know write multiple lines leave it open write multiple lines leave it open and then finally close it the file a pen one every time you do like a file append it has to go read the file in they are sorry let me rephrase that it has to
open the file put the text there and then close the file and so if you’re writing 20,000 lines it’s a lot more work whereas the file object can open it once you know write the 20,000 and close it right all at one time or you know in those steps if that makes sense yeah yeah there’s different ways of doing it you could use a loop to build a variable holding a lot of lines and then file up and once but if you have things that are happening in between so you would like to actually have the file kept open or writable or you want to
lock the file so others don’t write to it while you’re working with it you could also use the file object but yeah there’s there’s a lot of options there and of course the file object just gets more control of how you actually work with the file at one point I actually used the file object to instead of let’s say appending to a file you wanted to put text in the middle of the file or you wanted to let’s say remove something or replace something within the file the file open command will allow you to do
this whereas with the file append and the file read you would need to let’s say read out all of the content to available variable and then do all of your actions on that and then either delete the old file and then append to a new file it just it just it’s just different ways of doing the same thing where’s so here andI agree with everything Jackie just said and the other thing is you’re actually here I’m saying yeah we can we could can you hear us I hope you kid but the and of course
the file object even though it as with anything right it is lat adds a lot of options at the same time it makes it a little more complex it’s not as simple as the file append but it is worth the effort and so here I have one example here where I’m going to open a file so this is my file I’m going to open this file underscore object example text and I’m going to open it I’m gonna tell I want to open it with right privileges and this is telling it to use the utf-8 format and so I first I open it and store that in F I’m trying
to remember what is this line supposed to be here that shouldn’t be I don’t know what I think I had borrowed that from something sorry there we go and so let me go ahead and run it and so let me open that file object example dot txt where where oh it’s in the I didn’t do it in a subfolder file object whose ample of text my bad and this of course will open it right there then we lose Jackie Jackie there I think we lost him I see him on there but anyway so the length when I’m trying to use its writing it led you back maybe
hey yeah length and then close it so let me look go ahead and read look the whole thing run first oh that’s the wrong sorry that’s the wrong file I’m a all right final object example ah there we go okay and so look if I come in here see this says 23 right and I believe that’s that was 26 and of course now I think the files have locked unfortunate I’m switching between sight in in studio all right I’ll just stick with doing hair so so I’m gonna first right Joe was here oh the other thing I wanted to point out
was notice in here I’m not adding line returns right so I write the line Joe was here I write the line next line I get the length of it and then I’m gonna do a loop doing it a index and notice again no line returns and then the lights gonna get bigger and it closes it and so let me get through this here so first is 26 and 66 now it’s done and now when we open it in sight we’ll see the whole file and here should be 63 I’m not sure why is 63 I thought it was gonna be 66 but anyway you see what it’s doing
here is it’s it’s adding the line the line returns at the end of them automatically right and I just looped over here just showing how I can insert them dumped it all in there and then closed it and make sure it’s not required but you want to make sure that you close use the file close after just to make sure it frees it up for other programs and everything even if you don’t open this with the right only or read-only privileges or whatever because you can lock it I think you can use some other
codes and lock it from other programs like Excel if Excel has a CSV file open other programs can’t read it which is really annoying but but anyway make sure you close it after it’s done and now let’s go ahead and switch to the read file and here we’re gonna read this is the other one I wanted to point out right is so when we save it we load it and run it and the first thing says Joe was here right so this is where on this message box and then it’s gonna tell us where we are in that file so now we’re
at character 16 in that file and now notice I call this again and this is the thing to me that was really confusing was it reads the next line so in this file that was Joe was here and that was 12 and then it read the next line I called the exact same thing twice right this red line I called it once I did the towel just to let me know where I am and then I called it again and each time you call it it it moves on to the next row and that’s why this towel is helpful because it’ll tell you where you are in
the file yeah it moves them the point yeah it’s more it moves I can remember it’s called a specific thing but yeah the pointer within the file yeah yeah yeah go ahead yeah and as long as you use let’s say read line and write line and stuff like that it helps you with the line breaks and stuff like that but yeah you can you can move even more freely than that yeah yeah but that it was it was this was not intuitive and I also thought oh I’ll put read line you know 10 you know it doesn’t work like
that no you’d need to move the file pointer first yes to specify which Lion track to the read yeah and maybe I would do that with seek yes thank you I didn’t I didn’t add that here because I didn’t want to add I’ve virtually never use it I didn’t want to have too many things in here but go check the the file object you know link for support there are some other a couple other things like the seek was what Jackie just mentioned but by far the the redline and the clothes and the open right are the things you’re most
often going to use and so we were just hitting the high points the this next one I thought is a great example here let me you know that you load it it’s gonna read this full list file which is a very large file and basically it’s gonna it iterates over it and it’s gonna keep track of what row it’s in and then it’s gonna each time it goes over it it’s storing what’s in the in the line in this last line and then of course because it’s on the very lot until it’s down to the very last one it doesn’t
doing it in the very last line it will read it in and save it and close it and that’s gonna show us this just inserts commas into it but let me show you how quickly I’m gonna hit my Hotkey there and now it went over a million rows in my file right that was what was that like a second a half maybe so it it went down over a million rows and got the very last line of that file and so sometimes you want to know what you know I need to know what the last line was written to and so this is a super quick easy way to grab even in a very large
file grab that last row data so this at end of file that’s another one which I didn’t put in the cheat sheets but you know what I’ll add seek and I’ll add into file to the the the PowerPoint deck before I share it the contents because I mean it’s it’s two minutes right and you might need it did that make sense to everybody hopefully in then I think that’s actually the end of the the main scripts and we’re right at the hour but here are some other there’s a file system object there’s
some comma objects in a DLL call I think this is the DLL call that you can also use for looping over files for getting content actually let me see if I think I have I’ll demonstrate the scriptural quickly instead of talking too much about them so what number is on file system it’s sort of Windows shell well alright that was the file out whether the windows shell copy move this one it can copy like it’s going to move this is a large file I thought I had a different file ash I don’t know if that’s see I
don’t think that’s still where it was but let me I’ll give it a try and see if I run it it well I’m what’s cool about it now is yeah I don’t have the file there and I’m not going to go hunt for it but I had a different example of it I don’t think it was this one my fellow system oh maybe I you know I did it in this one so let’s let’s do this other one first year oh oh they’re all open I’m an idiot all right they’re open over here I’m sorry all right so the wind shall copy that
was that one that’s funny I didn’t think that file was there let me see let me see if I can get the path to that file real quickly it doesn’t really matter sorry guys could bear with me a second all right here is a movie know which script is running I’m just not sure so what I like about this one is it shows you your your status bar and I believe I can call this multiple times and it’ll have it gets added to this it they keep showing up in here and so it’s it’s a it’s a cool way that if I just want to
move it in actually right now I have it oh yeah I see I updated this function to where I could put in the word copy or the word move I don’t know where I saved it so my bad that’s why it’s this isn’t the right v1 the
windows file system object alright lets me exit another one so this just went and got it’s like the other one like I said we’re coming up at the hour or we’re past the hour but I’m just gonna demonstrate these and then we’ll pause and then we’ll stop the recording and then start a backup assumption demonstrate him but this is getting dumping a lot of the the same thing as some one of the other ones we demonstrated but it’s using a comma scripting file system object this does a similar thing except for it’s getting
let’s see is it this one this one gets the hierarchy I think of the files and this one has the other information it’s basically the same stuff and the this twin MGMT s it gives you a lot of you can point to a specific file and it will give you other information about that file so it was just tangentially related so I want to throw it in here all right so let me go ahead and stop recording and then you guys Oh Jackie’s made it sorry you there you go Jackie but I’m gonna I’m gonna hit the sink you yeah I’m oops I
hit the wrong button let me stop recording

Comments are closed.