AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

var + 1
Goto page 1, 2  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
staid
Guest





PostPosted: Sat May 06, 2006 10:39 am    Post subject: var + 1 Reply with quote

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.
Back to top
PhiLho



Joined: 27 Dec 2005
Posts: 6836
Location: France (near Paris)

PostPosted: Sat May 06, 2006 11:56 am    Post subject: Reply with quote

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!)
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
staid
Guest





PostPosted: Sat May 06, 2006 10:03 pm    Post subject: Thanks Reply with quote

Hi PhiLho,
I should be able to get it working now.
Your help is appreciated,
Thanks.
Staid
Back to top
SKAN



Joined: 26 Dec 2005
Posts: 8688

PostPosted: Sun May 07, 2006 8:25 pm    Post subject: Reply with quote

Dear Staid, Smile

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 Sad.

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



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, Smile
_________________
URLGet - Internet Explorer based Downloader
Back to top
View user's profile Send private message Send e-mail
SKAN



Joined: 26 Dec 2005
Posts: 8688

PostPosted: Sun May 07, 2006 8:27 pm    Post subject: Reply with quote

To the kind attention of this forum's Moderator:

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

Regards, Smile
_________________
URLGet - Internet Explorer based Downloader
Back to top
View user's profile Send private message Send e-mail
corrupt



Joined: 29 Dec 2004
Posts: 2485

PostPosted: Sun May 07, 2006 8:54 pm    Post subject: Reply with quote

Goyyah wrote:
To the kind attention of this forum's Moderator:

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

Regards, Smile

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... Wink
Back to top
View user's profile Send private message Visit poster's website
SKAN



Joined: 26 Dec 2005
Posts: 8688

PostPosted: Sun May 07, 2006 9:01 pm    Post subject: Reply with quote

Dear Corrupt, Smile

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, Smile
_________________
URLGet - Internet Explorer based Downloader
Back to top
View user's profile Send private message Send e-mail
corrupt



Joined: 29 Dec 2004
Posts: 2485

PostPosted: Sun May 07, 2006 9:45 pm    Post subject: Re: var + 1 Reply with quote

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 Smile . Elaborating on the description definitely wouldn't hurt Smile .
Back to top
View user's profile Send private message Visit poster's website
staid
Guest





PostPosted: Mon May 08, 2006 8:46 am    Post subject: place txt files into a dir and search from them Reply with quote

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 Smile }

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.
Back to top
SKAN



Joined: 26 Dec 2005
Posts: 8688

PostPosted: Mon May 08, 2006 12:49 pm    Post subject: Re: place txt files into a dir and search from them Reply with quote

Dear Staid, Smile

Thanks for explaining in detail.. Smile

    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 Shocked )

Regards, Smile
_________________
URLGet - Internet Explorer based Downloader
Back to top
View user's profile Send private message Send e-mail
staid



Joined: 08 May 2006
Posts: 10
Location: QLD Australia

PostPosted: Mon May 08, 2006 9:30 pm    Post subject: Goyyah's script Reply with quote

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.
Back to top
View user's profile Send private message
bLisTeRinG



Joined: 15 Nov 2004
Posts: 45
Location: Port Fairy

PostPosted: Tue May 09, 2006 4:39 am    Post subject: My arcane file lister Reply with quote

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 Mad


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"
Back to top
View user's profile Send private message Send e-mail Visit poster's website
SKAN



Joined: 26 Dec 2005
Posts: 8688

PostPosted: Tue May 09, 2006 7:31 am    Post subject: Reply with quote

Dear bLisTeRinG, Smile

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, Smile
_________________
URLGet - Internet Explorer based Downloader
Back to top
View user's profile Send private message Send e-mail
bLisTeRinG



Joined: 15 Nov 2004
Posts: 45
Location: Port Fairy

PostPosted: Tue May 09, 2006 9:45 am    Post subject: Nice Reply with quote

Yep, I get it! Cute. Thanks. Very Happy
Back to top
View user's profile Send private message Send e-mail Visit poster's website
SKAN



Joined: 26 Dec 2005
Posts: 8688

PostPosted: Tue May 09, 2006 10:41 am    Post subject: Re: Nice Reply with quote

Dear bLisTeRinG, Smile,

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

Regards, Smile
_________________
URLGet - Internet Explorer based Downloader
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group