0
0
Intro to Computingfundamentals~10 mins

Copying, moving, and deleting files in Intro to Computing - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to copy a file named 'data.txt' to 'backup.txt'.

Intro to Computing
copyfile('data.txt', [1])
Drag options to blanks, or click blank then click option'
A'data.txt'
B'data_backup.txt'
C'backup_data.txt'
D'backup.txt'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the source file name as destination, which overwrites the file.
Using a wrong file name that doesn't match the task.
2fill in blank
medium

Complete the code to move a file 'report.doc' to the folder 'archive/'.

Intro to Computing
move('report.doc', [1])
Drag options to blanks, or click blank then click option'
A'report_archive.doc'
B'archive/report.doc'
C'archive/'
D'report.doc'
Attempts:
3 left
💡 Hint
Common Mistakes
Using only the folder name without the file name.
Renaming the file incorrectly.
3fill in blank
hard

Fix the error in the code to delete the file 'temp.log'.

Intro to Computing
os.[1]('temp.log')
Drag options to blanks, or click blank then click option'
Aremove
Bdelete
Cerase
Ddel
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'delete' or 'erase' which are not valid functions.
Using 'del' which is a Python keyword, not a function.
4fill in blank
hard

Fill both blanks to copy 'image.png' to 'backup/image_backup.png' only if the file size is greater than 1000 bytes.

Intro to Computing
if os.path.getsize('image.png') [1] 1000:
    copyfile('image.png', [2])
Drag options to blanks, or click blank then click option'
A>
B<
C'backup/image_backup.png'
D'image_backup.png'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' causing the condition to be wrong.
Using a destination path without the folder.
5fill in blank
hard

Fill all three blanks to move all '.txt' files from 'docs/' to 'archive/' folder.

Intro to Computing
for file in os.listdir('docs/'):
    if file.endswith([1]):
        src = 'docs/' + file
        dst = [2] + file
        [3](src, dst)
Drag options to blanks, or click blank then click option'
A'.txt'
B'archive/'
Cmove
Dcopyfile
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'copyfile' instead of 'move' causing files to be copied, not moved.
Forgetting the dot in '.txt' causing no files to match.