AutoHotkey Community

It is currently May 27th, 2012, 8:42 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: var + 1
PostPosted: May 6th, 2006, 11:39 am 
Hi,

I am creating text files that have the contents of the cd drive listed into them.

I want to start at something like CD-Drive01.txt and add the next CD on from there. However, I don't want to keep typing the numbers 01, 02, etc. as I have been in a batch file I made to do this.

How can I use AutoHotKeys to check if CD-Drive01.txt is there and if it is, to make the next one available.

I figure it's something like -

var number = 01

loop
{
ifnot exist CD-Drive%number%.txt
fileappend c:\temp\cd_drive_contents.txt CD-Drive%number%.txt
else var number = %number%+1
}

I don't know if AutoHotKeys can give me a similar readout of a CD's contents as what the DOS commands can: DIR e: /S /A-D /ON > c:\temp\cd_drive_contents.txt but if anyone knows a way to use AHK for this too it would be nice not to have to call upon a batch file.

Please ask any questions if this is not clear, thanks in advance,
Staid.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 6th, 2006, 12:56 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
Almost there... You should check the manual for the exact syntax.
Code:
path = E:\destinationPath\
cdDriveContent = c:\temp\cd_drive_contents.txt
Run %comspec% /c dir e: /s /A-D /on > %cdDriveContent%, , Hide
Loop
{
   filename = %path%CD-Drive%A_Index%.txt
   If (!FileExist(filename))
   {
      FileMove %cdDriveContent%, %filename%
      Break
   }
}
(untested!)

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Thanks
PostPosted: May 6th, 2006, 11:03 pm 
Hi PhiLho,
I should be able to get it working now.
Your help is appreciated,
Thanks.
Staid


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 7th, 2006, 9:25 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Dear Staid, :)

I am curious to know what you are going to do with the created text files (the file listing of CD Contents).

Sometime before I created a script which does something very similar- a kind of CD Catologue app which will store the File listing for a CD/DVD in a text file. I used those text files to search for a particular file in my (Huge!)collection of free CD's that came along with Computer magazines.

90% through, I lost the script in a Hard Drive crash :(.

Anyways! I would like to quote the technique I used to name the text files.

Image

We can get the Unique CD Serial number - like what you see in the above snapshot...
and name the text file with it ..

Volume Serial Number is 1846-3CCB

For this CD with Serial number 1846-3CCB we can create a textfile named 1846-3CCB.txt and list the contents to it.

Code:
CDROM:="I:"  ; Replace the "I:" with your CD/DVD Drive letter
DriveGet, SerialNumber, Serial, %CDROM%
Textfile=% VolumeSerialHex(SerialNumber) ".txt"

;Check whether the file already exists and if not write the file listing
IfNotExist, %TextFile%
 Loop, %CDROM%\*.*, 0, 1
     FileAppend, %A_LoopFileLongPath%`n, %TextFile%

Run,  %TextFile%,,Max
Return

VolumeSerialHex(_Serial)
{
; by A.N.Suresh Kumar aka Goyyah - 2006-05-07

  SetFormat, integer, hex
  _Serial+=0
  SetFormat, integer, d
  StringReplace, _Serial, _Serial, 0x,, All
  StringUpper, _Serial, _Serial
  _Serial=00000000%_Serial%
  StringRight, _Serial, _Serial, 8
  StringMid, _S1, _Serial, 1, 4
  StringMid, _S2, _Serial, 5, 4
  _Serial = % _S1 "-" _S2
Return _Serial
}


Try the above code (make sure varible CDROM contains a valid drive letter).

However, REMEMBER that this technique does have limitations :

A Hard Disk Partition will have a new serial number every time it is formatted
and this is also applicable to Rewritable CD's.

Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 7th, 2006, 9:27 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
To the kind attention of this forum's Moderator:

Please give this topic a more descriptive title as you deem fit.

Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 7th, 2006, 9:54 pm 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
Goyyah wrote:
To the kind attention of this forum's Moderator:

Please give this topic a more descriptive title as you deem fit.

Regards, :)

The title seems relevant... (I'm not a moderator though). It's at least a bit better than HELP! PLEASE! or beginner question or need a script etc... ;)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 7th, 2006, 10:01 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Dear Corrupt, :)

Staid wrote:
How can I use AutoHotKeys to check if CD-Drive01.txt is there and if it is, to make the next one available.

He further wrote:
I don't know if AutoHotKeys can give me a similar readout of a CD's contents as what the DOS commands can: DIR e: /S /A-D /ON > c:\temp\cd_drive_contents.txt but if anyone knows a way to use AHK for this too it would be nice not to have to call upon a batch file.


... for which I took time to write an alternative solution & have posted it.
I am not arguing, but think I my request to the Moderator is fit.

Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: var + 1
PostPosted: May 7th, 2006, 10:45 pm 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
staid wrote:
How can I use AutoHotKeys to check if CD-Drive01.txt is there and if it is, to make the next one available.

var + 1
Increment the name of the text file...

It's all good though :) . Elaborating on the description definitely wouldn't hurt :) .


Report this post
Top
 Profile  
Reply with quote  
PostPosted: May 8th, 2006, 9:46 am 
Hi Goyyah,

About 18 months ago, I made a batch file to put a CD's contents into a txt file. I used it to name them with a number 001, 002, etc. and have been writing the number onto the CD and putting it into a CD folder.

After using AutoHotkeys, I thought there might be a quicker way that meant I didn't have to type in the number (and I have also been adding a description). I mean, the way I've been doing it is pretty quick... but if I could run a script - from a hotkey! - each time I burn a CD - that reports what number it is at the end of it, the process would take 15 seconds instead of 30 and involve only the original keystrokes. {exciting stuff :) }

I have a batch file that searches the folder of the txt files for phrases using the findstr /I command. (/I denotes that it is not case-sensitive).

I run the batch file from a quick launch icon. The batch file calls a vbscript for an input box that I type the search string into. Then, when the results appear in DOS, I can reference which CD has the contents that I want.

In case there are too many results, I added the options to add another search word - eg. batman *and* robin or remove a word from the results - eg. you search "race" and remove "car".

Anyway, I uploaded the batch and the vbscript files to my gmail page:

http://staid03.googlepages.com/txtfile if you want to see.

Thanks for your example of code,

Staid.


Report this post
Top
  
Reply with quote  
PostPosted: May 8th, 2006, 1:49 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Dear Staid, :)

Thanks for explaining in detail.. :)

    I am about to re-write my earlier script something like the following.

  • Only AHK - No Console Commands - No VB Scripting.
  • It will run silently in System tray and whenever it finds a New CD Serial Number will immediately
    prompt the user with a message box and will write the file listing if the user opts so!
  • Search Option for files and listing will be in HTML.

Please do post any suggestions you may have on the above.

And .. , did you try my code?

Thanks for the link you gave.. ( I never knew about googlepages.com though I have a gmail ID :shock: )

Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Goyyah's script
PostPosted: May 8th, 2006, 10:30 pm 
Offline

Joined: May 8th, 2006, 10:24 pm
Posts: 10
Location: QLD Australia
Hi Goyyah,

I ran the script you wrote and it works great. I like to add the size and date of each file - just because often I will have applications that I saved to disk and want to know the newest version.

As a beginner I don't fully understand how it worked, so, I when I get home tonight, I'll research some of the commands and their parameters.

Thanks,

Staid.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: My arcane file lister
PostPosted: May 9th, 2006, 5:39 am 
Offline

Joined: November 15th, 2004, 1:46 pm
Posts: 45
Location: Port Fairy
It took me ages to get this right and i too would like a neater solution.
My method appears as a right-click option for Folders.

Quote:
REGEDIT4

[HKEY_CLASSES_ROOT\Directory\shell\List Files]

[HKEY_CLASSES_ROOT\Directory\shell\List Files\command]
@="C:\\Progra~1\\Tools\\Util\\T.bat 3 %1 C:\\MyDocu~1\\MySett~1\\Desktop\\Tree.txt"


As you can see, I just reuse the same filename each time (embarassed). However, T.bat is called with command-line parameters 3 and the folder location. So I can use it for folders as well as Cd's. The first parameter (numeral 3 in this case) runs the following batch-file sub-routine:

Quote:
:tre
If "%dos%" == "4" Dir/s/a:-d/b %i% > %o%
If NOT "%dos%" == "4" Dir/s/a:-d/b/o:n/-p %i% > %o%
goto :x


The 'If dos is 4' check whether 4dos is the command shell and if so alters the specifics of the command, but basically a nice clean file-list, recursive, and retaining the path. The other batch-file sub-routines are for:

-folders recursive
-files and paths recursive with sizes
-files and paths recursive
-files and paths recursive with folders listed at top
-folders in current folder
-files in current folder
-applications recursive with paths

Effective and dependable! but could be a lot better. If you're going to have a go at it perhaps this list of options might help.
If you don't, I probably will eventually but I usually end up looking at this sort of thing just as it's needed (bad practice, i know). But I definately agree its a natural for ahk!

Hope this is some use.
gq

ps var++
pps lets call it "Folder and File Listing"


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 9th, 2006, 8:31 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Dear bLisTeRinG, :)

If you know the name of last file created (store it in an INI file or in the windows Registry)
Then the following code can help you.

For example: (If the last file created was Tree99.txt)

Code:
LastFileName=Tree99.txt

;Get Filename & Extension in seperate variables
SplitPath, LastFileName, , , OutExtension, OutNameNoExt,

NewFileName = % IncrementName(OutNameNoExt) "." OutExtension

Msgbox, % NewFileName
Return

IncrementName(nameNoExt)
{

/*
Written by Philippe Lhoste aka PhiLho
See origin post @ http://www.autohotkey.com/forum/viewtopic.php?t=8363
*/
   local d, dd

   Loop
   {
      ; Take out rightmost char (digit?)
      StringRight d, nameNoExt, 1
      StringTrimRight nameNoExt, nameNoExt, 1
      If d = 9
      {
         ; Propagate carry: continue
         dd = 0%dd%
      }
      Else If d between 0 and 8
      {
         ; Just increment this digit
         dd := (d + 1) . dd
         Break
      }
      Else
      {
         ; Not a digit: put back non digit char, add a 1
         nameNoExt = %nameNoExt%%d%1
         Break
      }
   }
   Return nameNoExt . dd
}



Hope this was of some help.

Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Nice
PostPosted: May 9th, 2006, 10:45 am 
Offline

Joined: November 15th, 2004, 1:46 pm
Posts: 45
Location: Port Fairy
Yep, I get it! Cute. Thanks. :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Nice
PostPosted: May 9th, 2006, 11:41 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Dear bLisTeRinG, :),

I just want to mention that your method of File listing can be done AHK Code alone.

Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Exabot [Bot], specter333, XstatyK and 59 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group