stibbar Posted February 23, 2012 Share Posted February 23, 2012 Hello all,I have been searching the forums, and I have not been able to find anything on copying a file and using the information in a text file for the source and destination. I am betting there is something out there and I suck at searching.so here is what i am trying to accomplish in a nutshell;create a GUI that asks you what directory you want to search. - Worksport specific file type list to a text file. - worksuse that text file to read the each line then copy the file to the same directory and add .OLD to it. - fail as a n00b scripterI have used autoit before and created some scripts to make life easy, but nothing really like this and I would like your input as I am stumped. I have tried fileread & filereadline, I know I am doing something stupid or forgetting something dumb. so anyone able to bring light to this i would appriciate it, and so would my head from banging it on the desk.Here is the code, it is simple to say the least, I also removed all the variables i had been using like @temp and things to rule out fat fingered code.#Include <File.Au3> #Include <String.Au3> #include <Array.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> local $copyandreplace = "C:\Temp\AUTOIT.OLD.txt" FileOpen($copyandreplace) while 1 $copy = FileRead($copyandreplace) ;~ $copy2 = FileReadLine($copyandreplace) ;lef this so you know i tried this as well. If @error = -1 Then ExitLoop FileCopy($copy, $copy &".old") WEnd FileClose($copyandreplace)Thanks In advance folks.Stibb Link to comment Share on other sites More sharing options...
JohnOne Posted February 23, 2012 Share Posted February 23, 2012 I do not quite understand what you are wanting to do. The best I can muster is that you want to rename the file. if that is true then look at the FileMove function and read its remarks. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
stibbar Posted February 23, 2012 Author Share Posted February 23, 2012 JohnOne Essentially what I am trying to do is use the text file as a way to list, in this case Microsoft App-V OSD files, with the full path. Then use that text file with a string of some type to pull the full path from the text and copy the file. In the text there is something like this D:APPV.OSD.testapplicationname0ApplicationOSD0.osd D:APPV.OSD.testapplicationname1ApplicationOSD1.osd D:APPV.OSD.testapplicationname2ApplicationOSD2.osd what I am am trying to figure out is how to pull each line so it reads it, then copies it with the .old added to the end so ending up with something along the lines of filecopy ("D:APPV.OSD.testapplicationname0ApplicationOSD0.osd, "D:APPV.OSD.testapplicationname0ApplicationOSD0.osd.old") I have over 2000 of these files i want to do it with varibles that read each line until it reaches the end of the file. I hope that makes more sense. /R Stibb Link to comment Share on other sites More sharing options...
stibbar Posted February 23, 2012 Author Share Posted February 23, 2012 69255 I tried that code, but I received H:Script.repositoryOSDSCRATCH OSD.au3 (37) : ==> Subscript used with non-Array variable.: For $i = 1 To $aCopy[0] For $i = 1 To $aCopy^ ERROR I am not familar with the [ ] so i will go poke around and trying and read up on those. /R Stibb Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted February 23, 2012 Moderators Share Posted February 23, 2012 (edited) Hi, Stibbar. How about something like this? #include <File.au3> $file = "C:TestTest.txt" $file_count_lines = _FileCountLines($file) for $i = 0 to $file_count_lines $output = FileReadLine($file, $i) FileCopy($output, $output & ".old", 1) Next You'll need to change your directory, of course. But this works for me for 100+ text files. Edited February 23, 2012 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
stibbar Posted February 23, 2012 Author Share Posted February 23, 2012 JLogan3o13 Thanks, that actually worked once i moved he file to something i had full access to, not even going to try and figure out why reading from temp was jacked up lol69255 once i moved the text file and added it also worked.local $file = "d:text.txt"Thank you both very much for the direction you all rock!On to the next issue and hopefully I can write that one to work the first time around hehe/RStibbar Link to comment Share on other sites More sharing options...
BrewManNH Posted February 23, 2012 Share Posted February 23, 2012 Are the files always named *.osd, and do you want to move or copy all the files in the folder with that extension to the new destination with a new extension? Because if they're all .osd file extensions and you want to copy all of them you could do it this way: FileCopy("C:temp*.osd", "C:tempNew*.osd.old", 9) If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
stibbar Posted February 23, 2012 Author Share Posted February 23, 2012 BrewManNH, thanks much for the input boss /R Stibb Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now