logo
down
shadow

How to check if file exists in Eiffel


How to check if file exists in Eiffel

Content Index :

How to check if file exists in Eiffel
Tag : development , By : Novi Indrayani
Date : November 28 2020, 04:01 AM

seems to work fine You can use {FILE_UTILITIES}.file_exists (the_file_name)
or (create {RAW_FILE}.make_with_name (the_file_name)).exists

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Python: Check if file from list exists, execute function only if it exists


Tag : python , By : user107021
Date : March 29 2020, 07:55 AM
I wish did fix the issue. You have a couple problems in your code.
First, chkifexists is returning as soon as it finds an existing file, so it never checks any remaining names; also, if no files are found then the hashcolumn and filepathNum are never set -- giving you the UnboundLocalError.
import os, csv

# store file attributes for easy modifications
# format is 'filename': (hashcolumn, filepathNum)
files = {
        'A.csv': (7, 5),
        'B.csv': (15, 5),
        'C.csv': (1, 0),
        }

class NoFilesFound(Exception):
    "No .csv files were found to clean up"

def chkifexists(somefiles):
    # load all three at once, but only yield them if filename
    # is found
    filesfound = False
    for fname, (hashcolumn, filepathNum) in somefiles.items():
        if os.path.isfile(fname):
            filesfound = True
            yield fname, hashcolumn, filepathNum
    if not filesfound:
        raise NoFilesFound

def removedupes(infile, outfile, hashcolumn, filepathNum):
    # this is now a single-run function
    r1 = file(infile, 'rb')
    r2 = csv.reader(r1)
    w1 = file(outfile, 'wb')
    w2 = csv.writer(w1)
    hashes = set()
    for row in r2:
        if row[hashcolumn] =="": 
            w2.writerow(row)       
            hashes.add(row[hashcolumn])  
        if row[hashcolumn] not in hashes:
            w2.writerow(row)
            hashes.add(row[hashcolumn])
    w1.close()
    r1.close()


def bakcount(origfile1, origfile2):
    '''This function creates a .bak file of the original and does a row count
    to determine the number of rows removed'''
    os.rename(origfile1, origfile1+".bak")
    count1 = len(open(origfile1+".bak").readlines())
    #print count1

    os.rename(origfile2, origfile1)
    count2 = len(open(origfile1).readlines())
    #print count2

    print str(count1 - count2) + " duplicate rows removed from " \
        + str(origfile1) +"!"


def CleanAndPrettify():
    print "Removing duplicate rows from input files..."
    try:
        for fname, hashcolumn, filepathNum in chkifexists(files):
            removedupes(
                   fname,
                   os.path.splitext(fname)[0] + "2.csv",
                   hashcolumn,
                   filepathNum,
                   )
            bakcount (fname, os.path.splitext(fname)[0] + "2.csv")
    except NoFilesFound:
        print "no files to clean up"

CleanAndPrettify()
def chkifexists(somefiles):
    # load all three at once, but only yield them if filename
    # is found
    for fname, (hashcolumn, filepathNum) in somefiles.items():
        if os.path.isfile(fname):
            filesfound = True
            yield fname, hashcolumn, filepathNum

def CleanAndPrettify():
    print "Removing duplicate rows from input files..."
    found_files = list(chkifexists(files))
    if not found_files:
        print "no files to clean up"
    else:
        for fname, hashcolumn, filepathNum in found_files:
            removedupes(...)
            bakcount(...)

Python check if file exists doesnt work although the file DO exists


Tag : python , By : nabbed
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , The reason is probably / in the beginning of '/outputs/topologia_wynik' + str(file_id) + '.top'. It means "outputs" folder should be under the root folder, and in your case it seems to be under the server working directory.
Why not pass os.path.join(app.config['OUTPUT_FOLDER'], 'topologia_wynik' + str(file_id) + '.top') to os.path.isfile() as you did with the input file name?

Check if a .txt file exists. FileWriter.exists method not working


Tag : java , By : Robby
Date : March 29 2020, 07:55 AM
To fix the issue you can do SOLVED!!! for the hand guys got it working. Appreciate it! , You have compilation error here:
FileWriter userData = new FileWriter(fileName);
if (userData.exists())
File userDataFile = new File(fileName);
if (userDataFile.exists())
FileWriter userData = new FileWriter(userDataFile);
userData.write(user + " ");
userData.write(ps);
userData.close();
System.out.println(new File(fileName).getAbsolutePath());

VB.NET: XMLWriter() check if directory exists and if file exists, otherwise create them


Tag : .net , By : jedameron
Date : March 29 2020, 07:55 AM
I hope this helps . I am running into a small bug in a vb.net console application I am working with right now. , This should work for you:
' Exctract the directory path
Dim xmlSaveDir=System.IO.Path.GetDirectoryName(xmlSaveLocation)

' Create directory if it doesn't exit
If (Not System.IO.Directory.Exists(xmlSaveDir)) Then
    System.IO.Directory.CreateDirectory(xmlSaveDir)
End If

' now, use a file stream for the XmlWriter, this will create or overwrite the file if it exists
Using fs As New FileStream(xmlSaveLocation, FileMode.OpenOrCreate, FileAccess.Write)
    Using writer As XmlWriter = XmlWriter.Create(fs)
        ' use the writer...
        ' and, when ready, flush and close the XmlWriter
        writer.Flush()
        writer.Close()
    End Using
    ' flush and close the file stream
    fs.Flush()
    fs.Close()
End Using

Eiffel: void safety, a concise way to test if an object exists and then call its feature


Tag : development , By : flesk
Date : March 29 2020, 07:55 AM
should help you out To avoid code duplication and multiple tests, the following code could be used:
l_foo := foo
if not attached l_foo then
    create l_foo
    foo := l_foo
end
l_foo.bark
Related Posts Related QUESTIONS :
  • Is (0*1*)* equal to (0 | 1)*?
  • How do I configure phpMyAdmin to start with a blank sql query from the SQL tab?
  • "Objects are not valid as a React child" Redux error when conditionally connecting a component?
  • Displacy results are not showing
  • Strapi / Graphql. What am i doing wrong?
  • How to add Search bar for django template?
  • lookup in presto using single column against a range in lookup table
  • How can you stop videos being stolen on website?
  • Can't code substitution happen in Hybrid Flow?
  • Removed widget remains on parent
  • setup saga middleware with redux-starter-kit's configureStore()
  • How to get cookies from response of scrapy splash
  • I need to do a firebase stream and not a Http Get
  • Unable to compile node-runtime
  • SQLSTATE[42S22]: Column not found: 1054 Unknown column '' in 'where clause'
  • How to extract only the number from a variable
  • disable linter in DAML studio
  • RxJS: How to set exhaustMap concurrent?
  • How to remove perforce (p4) on Ubuntu
  • How do they know mean and std, the input value of transforms.Normalize
  • Why this type is not an Interface?
  • SugarCRM Rest API set_relationship between Contacts and Documents
  • Jira dashboard organization
  • Web worker importScripts fails to place script variables in global scope
  • Always errors - The "path" argument must be one of type string, Buffer, or URL. Received type undefined
  • How to create an observable of a stream of infinite items
  • Not efficiently to use multi-Core CPU for training Doc2vec with gensim
  • webGL gl_Position value saving outside shaders
  • Is it okay for a resolver to have side effects besides resolving the type?
  • Move 32bit register into a 8 bit register
  • Is there a way to update, not overwrite, worker_env for a Dask YarnCluster within a script?
  • Lotus Notes Deployment
  • How Do I Add Active Directory To APIM Using Terraform?
  • How to get the old parameter values in Blazor OnParameterSet?
  • How to debug "ERROR: Could not reach the worker node."?
  • How chain indefinite amount of flatMap operators in Reactor?
  • extract dates and times from string in Redshift
  • How do I make a column of 3 cards match in height in bootstrapVue?
  • how to replace missing values from another column in PySpark?
  • only read last line of text file (C++ Builder)
  • Snakemake --forceall --dag results in mysterius Error: <stdin>: syntax error in line 1 near 'File' from Graphvis
  • How Can I Remove Demo Products From APIM Created With Terraform?
  • How to avoid cloning a big integer in rust
  • Break a row of words into word groups in Hive
  • How can I add a path variable to existing files in an Installshield project converted from MSI
  • Certain languages are not available in postman; is there a way to enable it?
  • Concatenation step of U-Net for unequal number of channels
  • HL Fabric - states, transactions but varied keys
  • How to handle "flood wait" errors when using telethon.sync?
  • Any way to make closure which takes a destructured array?
  • What is the Difference between @PeculiarVentures 's `webcrypto` and `node-webcrypto-ossl`?
  • DWG Sheet Combination failing on AutoDesk Forge
  • karate.log(args) on afterScenario hook is not embedded on surefire json file
  • How do I output latest distinct values of specific fields and all other colums?
  • Clarification on lit-element components and where to browse them
  • Will websockets over HTTP2 also be multiplexed in streams?
  • How to apply switch statement for multi columns in datatables
  • frobot framework - Usage outside testing
  • How do I build against the UCRT with mingw-w64?
  • How to use someClass.android.ts and someClass.ios.ts without errors
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com