FILE.COPY error on open file

BGI
Member Posts: 176
Hi all,
maybe stupid question but following scenario:
- I copy a file from pe. desktop to special folder using the navision command file.copy(origfilename,destfilename).
Now sometimes these files (pe. word doc) are still open by user, so he gets a error stating file is in use...so far no problem.
User closes word and want to copy again, but now error that destination file already exists.
This destination file indeed exists, and has 0bytes, and apparantly is held open by the navision client, because i cannot delete it.
Only when we close navision client, this file is being freed up and can be deleted.
Now my question:
- how can i see if a file is in use? (so i don't give the copy command).
- or can i force the destinationfile to be deleted?
Rgds
Benny
maybe stupid question but following scenario:
- I copy a file from pe. desktop to special folder using the navision command file.copy(origfilename,destfilename).
Now sometimes these files (pe. word doc) are still open by user, so he gets a error stating file is in use...so far no problem.
User closes word and want to copy again, but now error that destination file already exists.
This destination file indeed exists, and has 0bytes, and apparantly is held open by the navision client, because i cannot delete it.
Only when we close navision client, this file is being freed up and can be deleted.
Now my question:
- how can i see if a file is in use? (so i don't give the copy command).
- or can i force the destinationfile to be deleted?
Rgds
Benny
Rgds
Benny Giebens
Benny Giebens
0
Answers
-
EXISTS
Use this function to determine if a file exists.
[Ok :=] EXISTS(Name)
ERASE
Use this function to erase a file.
[Ok] := ERASE(Name)
You can always do a quick check & erase before you do the copy.
(Example)
If exists ('YourDrive:\YourDirectory\YourFile.txt') then
erase ('YourDrive:\YourDirectory\YourFile.txt');
>>your copy command here
**depending on what's going on with this file you can use F1 help to read about
Currfile.CLOSE; command
We use it on a dataport to move a file from it's original folder to a saved folder once the data has been imported.
here's an example.
Text Constant
FilePath = I:\Internet Data Feed\Completed Import\
OnPostDataport()CurrFile.CLOSE; <<close the file SavedFileName := FORMAT(WORKDATE,0,'<Year4>'+'-'+'<Month Text,3>'+'-'+'<Day,2>')+'.txt'; <<Autocreate a date oriented file name FILE.COPY(CurrDataport.FILENAME,FilePath+SavedFileName);<<copy the file to new location ERASE(CurrDataport.FILENAME);<<delete file from original location
0 -
Hi Harry,
i know those commands, no problem there.
But do pe. the following:
Open word document test1.doc in word.
Do in navision: file.copy(test1.doc,copytest1.doc).
You will get an error that file is open.
Close word, and in the same navision session (without closing your navision client), do the copy a second time.
You will get an error that copytest1.doc already exists.
Try to delete copytest1.doc and it will not work.
When you close the navision client, then the file copytest1.doc is deleted.
Thats my problem....Rgds
Benny Giebens0 -
Maybe you can try to open the file in Writemode first. If that succeeds, you know that the file is not in use:
File.WRITEMODE(TRUE); IF NOT(File.OPEN('c:\yourfile')) THEN MESSAGE('File does not exists or is in use'); File.CLOSE;
If it succeeds, you can close the file and copy it.No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)0 -
Luc,
indeed simple but working....even did
File.open(...);
File.close;
file.copy(..)
And it works ....stupid but it solves the problem.
Thnx
BennyRgds
Benny Giebens0 -
But FILE.CLOSE doesn't exist in NAV 5.0 Sp1.
Is the file automatically closed or there is another method to close it?
Thank you0 -
File.CLOSE does exists in my version of NAV 5.0 SP1:
Quoting on-line help:CLOSE (File)
Use this function to close a file which has been opened by OPEN (File).
File.CLOSE
File
Data type: file
Use this variable to refer to the file.
Comments
If the file is not open, a run-time error will occur.No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)0 -
Yep,
Also works in 5.1, that is the version we are using...Rgds
Benny Giebens0 -
I think to have solved.
I tried FILE.CLOSE(FileName) where filename was my text variable in the same way of FILE.ERASE(FileName) without using the variable of type FILE .
Thank you0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions