Page 1 of 2 12>
Topic Options
#24819 - 2002-07-11 02:45 PM How to find a file????
atiisler Offline
Fresh Scripter

Registered: 2002-07-10
Posts: 34
Hi,
I am new to Kixtart and have a problem I can't solve.

I need to first read thru a folder and locate a particular file. The problem is I don't know the file name only the extension. There is only one file with this extension. I know how to read the files in folder, but I do not know how to capture the filename of the file when read. Then once I read the file I am looking for I need to assign this text to a variable. [Confused]

Top
#24820 - 2002-07-11 02:48 PM Re: How to find a file????
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
welcome on board.

$filename=DIR("path\*.ext")

$filename will have the file name in it.

cheers,
_________________________
!

download KiXnet

Top
#24821 - 2002-07-11 03:19 PM Re: How to find a file????
atiisler Offline
Fresh Scripter

Registered: 2002-07-10
Posts: 34
Thank you soo much...I was actually using something similar but all I was doing was looping

Code:
;$id = dir("c:\lotus\notes\data\*.*")
;while $id <> "" and @error = 0

; ? $id
; ;if $id = "*.id"
; ; ? "Eureka, I did it"
; ;endif


; $id = dir() ;retrieve next file
;loop

I didn't realize I code specify the extension in the DIR line...

Thank you again for such a quick response....
Also....can I use the command Xcopy with kixtart?
I know copy is available but does not have the switches of Xcopy like /i ( which will create a folder if not already there)

Thanks again

Top
#24822 - 2002-07-11 03:21 PM Re: How to find a file????
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yes you can.

you just need to shell out from kix to use external programs.

for xcopy something like this:
shell "%comspec% /c xcopy /switches c:\temp c:\windows"

cheers,
_________________________
!

download KiXnet

Top
#24823 - 2002-07-11 05:03 PM Re: How to find a file????
atiisler Offline
Fresh Scripter

Registered: 2002-07-10
Posts: 34
I don't mean to sound so dumb....but I really do not understand that line of code..I tried to use it and got zip....
if i put that line of code in can i then use the XCOPY command in kixtart...if not where would I put the file copy information? Thanks for all your help

Top
#24824 - 2002-07-11 05:07 PM Re: How to find a file????
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
shell -command for using external commands
%compsec% - environment variable for real path to command interpreter.
/c - opens command interpreter for executing command and then exit
xcopy - your dos xcopy
/switches - what ever switches you want to use

doing a shell "something" is similar to if you run from start menu->run: "something"

cheers,
_________________________
!

download KiXnet

Top
#24825 - 2002-07-11 05:28 PM Re: How to find a file????
atiisler Offline
Fresh Scripter

Registered: 2002-07-10
Posts: 34
Would this be accurate way to code if I wanted to copy file names.nsf to folder test, both on C: drive of local machine?

shell "%comspec% /c xcopy /i c:\names.nsf C:test"
if @error = 0
? "found"
else
? "not found"
endif

Top
#24826 - 2002-07-11 05:34 PM Re: How to find a file????
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
The error evaluation will not work for SHELLed out stuff. Your missing the backslashes in your target directory. Why not use the build-in COPY command? For example,
code:
COPY 'c:\names.nsf' 'C:\test\'

for a single-file-copy.
_________________________
There are two types of vessels, submarines and targets.

Top
#24827 - 2002-07-11 05:40 PM Re: How to find a file????
atiisler Offline
Fresh Scripter

Registered: 2002-07-10
Posts: 34
That was just an example. What I really want to do is copy a file ( the one I found using the DIR command you sent me that I only knew ext for) from the users local drive to a network drive and if the folder does not exist to create it on the fly and copy the file to it. ( the XCOPY switch /i will create a folder, file, etc that does not exist)

Since this is my main goal can it be done?
I really appreciate all your help.

Top
#24828 - 2002-07-11 05:47 PM Re: How to find a file????
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Hope, this helps.

code:
$sourcefile='c:\temp\test.txt'
$targetdir='\\server\share\folder\'
if not exist($targetdir)
md $targetdir
if @ERROR
? ''+@ERROR+' '+@SERROR'+' creating directory '+$targetdir
endif
endif
copy $sourcefile $targetdir
if @ERROR
? ''+@ERROR+' '+@SERROR'+' copying file '+$sourcefile+' to directory '+$targetdir
endif

_________________________
There are two types of vessels, submarines and targets.

Top
#24829 - 2002-07-11 06:15 PM Re: How to find a file????
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
jens, the error actually works for some shelled commands.
I used it with compination of find and ping and got nice fileless ping solution.

cheers,
_________________________
!

download KiXnet

Top
#24830 - 2002-07-11 06:25 PM Re: How to find a file????
atiisler Offline
Fresh Scripter

Registered: 2002-07-10
Posts: 34
That code makes total sense...and most of it works. But for some reason this line is not finding my file...

$sourcefile='c:\Lotus\Notes\Data\names.nsf'

the directory is being created but no file is copied. I checked to make sure file exists and it does...any ideas

Thank you thank you again

Top
#24831 - 2002-07-11 06:31 PM Re: How to find a file????
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
That's why I put in the error checking code. What is the error message generated?
_________________________
There are two types of vessels, submarines and targets.

Top
#24832 - 2002-07-11 07:06 PM Re: How to find a file????
atiisler Offline
Fresh Scripter

Registered: 2002-07-10
Posts: 34
Sorry, it did work. I just had a wrong puctuation.

Why does it seem like the things that should be easy just don't seem to be. I am trying to create a variable that contains the value of a previous variable. Shouldn't it just be

$x = $y

with $y now being whatever $x was..???

Top
#24833 - 2002-07-11 07:10 PM Re: How to find a file????
atiisler Offline
Fresh Scripter

Registered: 2002-07-10
Posts: 34
it does....my typing is a bit to be desired..so an extra space here or there sure makes a diffrence in the outcome....

You guys are really a great help....

Top
#24834 - 2002-07-11 07:13 PM Re: How to find a file????
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
atiisler, you asked:
quote:

$x = $y

with $y now being whatever $x was..???

no. it's actually vice versa [Big Grin]
_________________________
!

download KiXnet

Top
#24835 - 2002-07-11 08:00 PM Re: How to find a file????
atiisler Offline
Fresh Scripter

Registered: 2002-07-10
Posts: 34
why won't this work:

code
$id = file name found previously

$sourcefile="c:\Lotus\Notes\Data\names.nsf"

$targetdir="\\orrm\domino\local_notes\" + "$id"

if not exist($targetdir)
md $targetdir

copy $sourcefile $targetdir

When I run this the folder is created in the right target directory with the right name but then when I get to the copy statement I get and error that says "system can not find path specified" showing the correct paths for copying from and to...

Once I get this part I will be almost done.....

Top
#24836 - 2002-07-11 08:03 PM Re: How to find a file????
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
dude, your targetdir is actually file path.
try with this:
code:
$id = file name found previously

$sourcefile="c:\Lotus\Notes\Data\names.nsf"
$targetdir="\\orrm\domino\local_notes\"
if not exist($targetdir)
md $targetdir
copy $sourcefile $targetdir + "$id"

_________________________
!

download KiXnet

Top
#24837 - 2002-07-11 08:04 PM Re: How to find a file????
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Are you sure that's what you want? Create a directory that includes the filename?
_________________________
There are two types of vessels, submarines and targets.

Top
#24838 - 2002-07-11 09:11 PM Re: How to find a file????
atiisler Offline
Fresh Scripter

Registered: 2002-07-10
Posts: 34
I am a Dudette ;}

What I am trying to do is create a script that copies the file names.nsf into a folder that is created using the *.id file. This file is going to be diffrent for each user, the only similarity is the .id extension. Once I capture this file using

code:
$id = dir("c:\lotus\notes\data\*.id")
if
@error = 0
? "no error"
else
@error = 1
? "there is an error"+ @serror+"You should notify the Administrator"
endif

What I want to do then is to create a folder on the network and name it using the .id file for identification of the user. That is why i needed to create the value of $id variable.
After the folder is created I need to then copy the name.nsf for a particular user and copy it to the folder that was created with .id file. It doesn't really matter that the folder is named the same( just identification purposes) as the file I located since the file I want to copy
is a diffrent file altogether.
So what I need to do is pull the names.nsf file from the local user and copy it into the folder I created on the netork.

If I use the the code you last sent it copies the .id file not the names.nsf which is the source file($sourcefile)
I can accomplish this if I hard code the $targetdir as such.

Code:
$targetdir="\\orrm\domino\local_notes\atiisler.id"

Everything works fine then. The atiisler.id folder is created and the names.nsf file is copied into it. The problem is that every user has a diffrent .id file and I would have to hardcode it for over 100 users. So I want to set it up based on the .id file that is found. And if that user doesn't have a folder to create it. Does this help? What I am trying to do is to create a backup of a file for Lotus notes. The .nsf is = .pst, but notes does load to server only on local station which is not backed up daily the server is. We need to do this for purposes of restoration.
Sorry so lenghy guys.......Thanks AGAIN

Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 774 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.074 seconds in which 0.028 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org